C++ Online Quiz


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 - A trigraph character begins with

A - #

B - ##

C - ?

D - ??

Answer : C

Explaination

Few characters have alternative representation and start with ??. Eg. Fro [ equivalent is ??(

Q 2 - From the below class choose the proper definition of the member function f().

template <class T>

class abc {
   void f();
};

A - template <class T>

    void abc<T>::f() { }

B - template<class T>

    void abc::f() { }

C - template<T>

    void abc<class T>::f() { }

D - template<T>

    void abc<T>::f() { }

Answer : A

Explaination

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

#include<iostream>

using namespace std;
main() { 

   int i = 1, j = 2, k = 3, r; 

   r = (i, j, k);

   cout<<r<<endl;

}

A - 1

B - 2

C - 3

D - Compile Error

Answer : C

Explaination

Comma is called as the separator operator and the associativity is from left to right. Therefore ‘k’ is the expressions resultant.

#include<iostream>

using namespace std;
main() { 

   int i = 1, j = 2, k = 3, r; 

   r = (i, j, k);

   cout<<r<<endl;

}

Q 4 - 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() {
   Base *p = new Derived(); 
   
   p->f();
}

A - Base

B - Derived

C - Compile error

D - None of the above.

Answer : A

Explaination

The method f() is not overridden therefore as per the pointer type respective method is called.

#include<iostream>

using namespace std;
class Base {
public:
   void f() {
      cout<<"Base\n";
   }
};
class Derived:public Base {
public:
   void f() {
      cout<<"Derived\n";
   }
};
main() {
   Base *p = new Derived(); 
   
   p->f();
}

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 - 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 - 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 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 - Identify the C++ compiler of Linux

A - cpp

B - g++

C - Borland

D - vc++

Answer : B

Explaination

g++ is GNU C++ compiler for linux. Borland and vc++ (Microsoft visual c++) for windows.

Q 10 - i) Exceptions can be traced and controlled using conditional statements.

ii) For critical exceptions compiler provides the handler

A - Only (i) is true

B - Only (ii) is true

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

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

Answer : B

Explaination

Conditional statements are used to take alternate actions depending upon certain condition but not multi branching. C++ too provides some critical exception handlers.

cpp_questions_answers.htm
Advertisements