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 - What is the output of the following program?

#include<iostream>

using namespace std;
class abc { 
   void f();
   void g();
   int x;
};

main() {
   cout<<sizeof(abc)<<endl;
}

A - 12

B - 4

C - 8

D - Compile error

Answer : B

Explaination

Only the class member variables constitutes as the size of the class or its object.

#include<iostream>

using namespace std;
class abc { 
   void f();
   void g();
   int x;
};
main() {
   cout<<sizeof(abc)<<endl;
}

Answer : C

Explaination

If no access specifiers are specified for structure variables/functions, then the default is considered as public.

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 - Choose the Object oriented programming language from below.

A - C++

B - Small talk

C - Simula

D - All the above.

Answer : D

Explaination

Q 5 - Which operator is used to resolve the scope of the global variable?

A - −>

B - .

C - *

D - ::

Answer : D

Explaination

Scope resolution operator is used to resolve for the global scope of a variable if the local and global variables conflict by name.

Q 6 - i) single file can be opened by several streams simultaneously.

ii) several files simultaneously can be opened by a single stream

A - (i) and (ii) are true

B - (i) and (ii) are false

C - Only (i) is true

D - Only (ii) is true

Answer : C

Explaination

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

#include<iostream>

using namespace std;
main() {
   enum { 
      india, is = 7, GREAT 
   };

   cout<<india<<" "<<GREAT;
}

A - 0 1

B - 0 2

C - 0 8

D - Compile error

Answer : C

Explaination

0 8, enums gives the sequence starting with 0. If assigned with a value the sequence continues from the assigned value.

#include<iostream>

using namespace std;
main() {
   enum { 
      india, is = 7, GREAT 
   };

   cout<<india<<" "<<GREAT;
}

Q 8 - What is the size of the following union definition?

#include<iostream>

using namespace std;
main() {
   union abc { 
      char a, b, c, d, e, f, g, h; 
      
      int i;
   };
   cout<<sizeof(abc);
}

A - 1

B - 2

C - 4

D - 8

Answer : C

Explaination

union size is biggest element size of it. All the elements of the union share common memory.

#include<iostream>

using namespace std;
main() {
   union abc { 
      char a, b, c, d, e, f, g, h; 
      
      int i;
   };
   cout<<sizeof(abc);
}

Q 9 - The default executable generation on UNIX for a C++ program is ___

A - a.exe

B - a

C - a.out

D - out.a

Answer : C

Explaination

“a.out” is the default name of the executable generated on both the UNIX and Linux operating systems.

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

#include<iostream>

using namespace std;
void main() {
   char s[] = "C++";
   
	cout<<s<<" ";
	s++;
	cout<<s<<" ";
}

A - C++ C++

B - C++ ++

C - ++ ++

D - Compile error

Answer : D

Explaination

‘s’ refers to a constant address and cannot be incremented.

#include<iostream>

using namespace std;
void main() {
   char s[] = "C++";
   
	cout<<s<<" ";
	s++;
	cout<<s<<" ";
}

cpp_questions_answers.htm

Advertisements