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 - Choose the operator which cannot be overloaded.

A - /

B - ()

C - ::

D - %

Answer : C

Explaination

Scope resolution (::) is not permitted to be overloaded.

Q 2 - A user defined header file is included by following statement in general.

A - #include “file.h”

B - #include <file.h>

C - #include <file>

D - #include file.h

Answer : A

Explaination

With the syntax as in (a) the compiler first looks for the file in the present working directory and then in the default include path if not found.

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;
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

The method f() inherited from Base is referred using :: operator.

#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 - HAS-A relationship between the classes is shown through.

A - Inheritance

B - Container classes

C - Polymorphism

D - None of the above.

Answer : B

Explaination

A class containing anther class object as its member is called as container class and exhibits HAS A relationship.

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

#include<iostream>

using namespace std;
main() {
   short unsigned int i = 0; 
   
   cout<<i--;
}

A - 0

B - Compile error

C - 65535

D - 32767

Answer : A

Explaination

0, with post decrement operator value of the variable will be considered as the expression’s value and later gets decremented

#include<iostream>

using namespace std;
main() {
   short unsigned int i = 0; 
   
   cout<<i--;
}

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

#include<iostream>

using namespace std;
main() { 
   int a[] = {1, 2}, *p = a;
   
   cout<<p[1]; 
}

A - 1

B - 2

C - Compile error

D - Runtime error

Answer : B

Explaination

as ‘p’ holds the base address then we can access array using ‘p’ just like with ‘a’

#include<iostream>

using namespace std;
main() { 
   int a[] = {1, 2}, *p = a;
   
   cout<<p[1]; 
}

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 - 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 : B

Explaination

After s++, s points the string “++”.

#include<iostream>

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

cpp_questions_answers.htm

Advertisements