C++ Online Quiz


Advertisements


Following quiz provides Multiple Choice Questions (MCQs) related to C++ Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - The default access specifer for the class members is

A - public

B - private

C - protected

D - None of the above.

Answer : B

Explaination

If a member/s appear in the class with following no access specifier, the default is private.

Q 2 - Which data type can be used to hold a wide character in C++?

A - unsigned char;

B - int

C - wchar_t

D - none of the above.

Answer : C

Explaination

wchar_t is the data type using which we can hold Unicode characters.

Q 3 - The following operator can be used to calculate the value of one number raised to another.

A - ^

B - **

C - ^^

D -None of the above

Answer : D

Explaination

There is no such operator in C/C++.

Q 4 - Escape sequence character '\0' occupies __ amount of memory.

A - 0

B - 1

C - 2

D - 4

Answer : B

Explaination

As it is also a character is occupies 1 byte of memory.

Q 5 - What is the output of the following program?

#include<iostream>

using namespace std;
main() { 
   int const a = 5;
   
   a++; 
   cout<<a; 
}

A - 5

B - 6

C - Runtime error

D - Compile error

Answer : D

Explaination

Compile error - constant variable cannot be modified.

Answer : B

Explaination

Defining a templated class is defining a generic class. Hence functionality of the class is generalized for several types, if applicable.

Q 7 - What is the output of the following program?

#include<iostream>

using namespace std;
main() { 
   const int a = 5;
   
   a++; 
   cout<<a; 
}

A - 5

B - 6

C - Runtime error

D - Compile error

Answer : D

Explaination

Compile error - constant variable cannot be modified.

#include<iostream>

using namespace std;
main() { 
   const int a = 5;
   
   a++; 
   cout<<a; 
}

Q 8 - What will be the output of the following program?

#include<iostream>
#include<string.h>

using namespace std;
main() {
   cout<<strcmp("strcmp()","strcmp()");
}

A - 0

B - 1

C - -1

D - Invalid use of strcmp() function

Answer : A

Explaination

0, strcmp return 0 if both the strings are equal

#include<iostream>
#include<string.h>

using namespace std;
main() {
   cout<<strcmp("strcmp()","strcmp()");
}

Q 9 - Special symbol permitted with in the identifier name.

A - $

B - @

C - _

D - .

Answer : C

Explaination

The only permitted special symbol is under score (_) in the identifier.

Q 10 - What is the output of the following program?

#include<iostream>

using namespace std;
main() {
   char s[] = "Fine";
	*s = 'N';
   
   cout<<s<<endl;
}

A - Fine

B - Nine

C - Compile error

D - Runtime error

Answer : B

Explaination

*s=ā€™Nā€™, changes the character at base address to ā€˜Nā€™.

#include<iostream>

using namespace std;
main() {
   char s[] = "Fine";
	*s = 'N';
   
   cout<<s<<endl;
}

cpp_questions_answers.htm

Advertisements