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 operator is required to be overloaded as member function only?

A - _

B - _ _

C - ++ (postfix version)

D - =

Answer : D

Explaination

Overloaded assignment operator does the job similar to copy constructor and is required to be overloaded as member function of the class.

Q 3 - In the following program f() is overloaded.

void f(int x) {

}

int f(signed x) { 
   return 1;
}

main() {

}

A - True

B - False

Answer : B

Explaination

No, as both the functions arguments is same and compiler ignores return type to consider overloading though different in return type.

Q 4 - The pointer which stores always the current active object address is __

A - auto_ptr

B - this

C - p

D - none of the above.

Answer : B

Explaination

this is the keyword and acts as a pointer which always holds current active objects.

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

#include<iostream>

using namespace std;
class Base {
public:
   void f() { 
      cout<<"Base\n";
   }
};
class Derived:public Base {
public: 
   void f() {
      cout<<"Derived\n";
   };
};
main() { 
   Derived obj; 
   obj.Base::f();
}

A - Base

B - Derived

C - Compile error

D - None of the above.

Answer : A

Explaination

Base object cannot refer to Derived members.

#include<iostream>

using namespace std;
class Base {
public:
   void f() { 
      cout<<"Base\n";
  }
};
class Derived:public Base {
public: 
   void f() {
      cout<<"Derived\n";
   };
};
main() { 
   Derived obj; 
   obj.Base::f();
}

Q 6 - With respective to streams >> (operator) is called as

A - Insertion operator

B - Extraction operator

C - Right shift operator

D - Left shift operator

Answer : B

Explaination

It extracts the data from stream into variables.

Q 7 - i) Exception handling technically provides multi branching.

ii) Exception handling can be mimicked using ‘goto’ construct.

A - Only (i) is true

B - Only (ii) is true

C - Both (i) & (ii) are true

D - Both (i) && (ii) are false

Answer : A

Explaination

goto just does the unconditional branching.

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

#include<iostream>

using namespace std;
main() { 
   float t = 2;
	
	switch(t) {
      case 2: cout<<”Hi”;
		default: cout<<"Hello";
	}
}

A - Hi

B - HiHello

C - Hello

D - Error

Answer : D

Explaination

Error, switch expression can’t be float value

#include<iostream>

using namespace std;
main() { 
   float t = 2;
	
	switch(t) {
		case 2: cout<<”Hi”;
		default: cout<<"Hello";
	}
}

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