C++ Programming Questions Useful for all Companies Interviews, UGC-NET, GATE EXAM PART- 2
. What is the output of this program? 1.#include 2.using namespace std; 3.void duplicate (int& a, int& b, int& c) 4.{ 5.a *= 2; 6.b *= 2; 7.c *= 2; 8.} 9.int main () 10.{ 11.int x = 1, y = 3, z = 7; 12.duplicate (x, y, z); 13.cout << x << y << z; 14.return 0; 15.} a) 1468 b) 2812 c) 2614 d) none of the mentioned View Answer Answer:c
. What is the use of functor? a) It makes the object “callable” like a function. b) It makes the class “callable” like a function. c) It makes the attribute “callable” like a function. d) none of the mentioned View Answer Answer:a Pick out the correct option. a) References automatically dereference without needing an extra character. b) References automatically dereference with an extra character. c) Reference will not dereference d) none of the mentioned View Answer Answer:a
1. Which is used to tell the computer that where a pointer is pointing to? a) dereference b) reference c) heap operations d) none of the mentioned View Answer Answer:a Explanation:None. 2. Which is used to do the dereferencing? a) pointer without asterix b) value without asterix c) pointer with asterix d) value with asterix View Answer Answer:c
4. What is the output of this program? 1.#include <iostream> 2.using namespace std; 3.int main() 4.{ 5.int a, b; 6.int* c; 7.c = &a; 8.a = 200; 9.b = 200; 10.*c = 100; 11.b = *c; 12.cout << *c << " " << b; 13.return 0; 14.} a) 100 200 b) 100 0 c) 200 200 d) 100 100 View Answer Answer:d
5. What is the output of this program? 1.#include <iostream> 2.using namespace std; 3.int main() 4.{ 5.int x; 6.int *p; 7.x = 5; 8.p = &x; 9.cout << *p; 10.return 0; 11.} a) 5 b) 10 c) memory address d) none of the mentioned View Answer Answer:a
7. What is the output of this program? 1.#include <iostream> 2.using namespace std; 3.int main() 4.{ 5.int x = 9; 6.int* p = &x; 7.cout << sizeof(p); 8.return 0; 9.} a) 4 b) 2 c) Depends on compiler d) none of the mentioned View Answer Answer:c
1. Which operator works only with integer variables? a) increment b) decrement c) both a & b d) None of the mentioned View Answer Answer:c Explanation:None. 2. How many types are there in increment/decrement operator? a) 1 b) 2 c) 3 d) 4 View Answer Answer:b
3. Pick out the correct statement. a) Increment operator ++ adds 1 to its operand b) Increment operator ++ adds 2 to its operand c) Decrement operator ++ subtracts 1 to its operand d) None of the mentioned View Answer Answer:a Which symbol is used to create multiple inheritance? [A] Dot 0% [B] Comma 0% [C] Dollar 0% [D] None of the mentioned 0% Answer: B. Comma
9. What does the dereference operator will return? a) rvalue equivalent to the value at the pointer address. b) lvalue equivalent to the value at the pointer address. c) it will return nothing d) none of the mentioned View Answer Answer:b Explanation:It operates on a pointer variable, and returns an l-value equivalent to the value at the pointer address. 10. Pick out the correct statement. a) The NULL pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to NULL. b) The NULL pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to memory address. c) both a & b d) none of the mentioned View Answer Answer:a
4. What is the output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int a = 21; 6.int c ; 7.c = a++; 8.cout << c; 9.return 0; 10.} a) 21 b) 22 c) 23 d) 20 View Answer Answer:a
. What is the output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int x = 5, y = 5; 6.cout << ++x << --y << endl; 7.return 0; 8.} a) 55 b) 64 c) 46 d) 45 View Answer Answer:b
1. How many types of representation are in string? a) 1 b) 2 c) 3 d) 4 View Answer Answer:b 2. What is the header file for the string class? a) #include<ios> b) #include<str> c) #include<string> d) None of the mentioned View Answer Answer:c
3. Which is used to return the number of characters in the string? a) length b) size c) both a & b d) None of the mentioned View Answer Answer:c
9. Pick out the correct statement a) Preincrement is faster than postincrement. b) postincrement is faster than preincrement. c) Both a & b d) None of the mentioned View Answer Answer:a Explanation:Because preincrement take one byte instruction & post increment takes two byte instruction. 10. Which concepts does the preincrement uses? a) call by value b) call by reference c) queue d) None of the mentioned View Answer Answer:b
7. What is the output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int x = 5, y = 5, z; 6.x = ++x; y = --y; 7.z = x + ++x; 8.cout << z; 9.return 0; 10.} a) 11 b) 12 c) 13 d) 14 View Answer Answer:d
What is the output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int x = 5, y = 5, z; 6.x = ++x; y = --y; 7.z = x++ + y--; 8.cout << z; 9.return 0; 10.} a) 10 b) 11 c) 9 d) 12 View Answer Answer:a
What is the output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int num1 = 5; 6.int num2 = 3; 7.int num3 = 2; 8.num1 = num2++; 9.num2 = --num3; 10.cout << num1 << num2 << num3; 11.return 0; 12.} a) 532 b) 235 c) 312 d) 311 View Answer Answer:d
. Which method do we use to append more than one character at a time? a) append b) operator+= c) data d) both a & b View Answer Answer:d . Which is also called as abstract class? a) virtual function b) pure virtual function c) derived class d) None of the mentioned View Answer Answer:b
1. Which class is used to design the base class? a) abstract class b) derived class c) base class d) None of the mentioned View Answer Answer:a Explanation:None. 2. Which is used to create a pure virtual function ? a) $ b) =0 c) & d) ! View Answer Answer:b
What is the output of this program? 1.#include <iostream> 2.#include <string> 3.using namespace std; 4.int main () 5.{ 6.string str ("microsoft"); 7.string::reverse_iterator r; 8.for (r = str.rbegin() ; r < str.rend(); r++ ) 9.cout << *r; 10.return 0; 11.} a) microsoft b) micro c) tfosorcim d) tfos View Answer Answer:c
8. What is meant by pure virtual function? a) Function which does not have definition of its own. b) Function which does have definition of its own. c) Function which does not have any return type. d) None of the mentioned View Answer Answer:a Explanation:As the name itself implies, it have to depend on other class only. 9. Pick out the correct option. a) We cannot make an instance of an abstract base class b) We can make an instance of an abstract base class c) Both a & b d) None of the mentioned View Answer Answer:a Explanation:None.
10. Where does the abstract class is used? a) base class only b) derived class c) both a & b d) None of the mentioned View Answer Answer:a 3. To which type of class, We can apply RTTI? a) Encapsulation b) Polymorphic c) Derived d) None of the mentioned View Answer Answer:b
1. What is the Run-Time Type Information? a) Information about an object’s datatype at runtime b) Information about the variables c) Information about the given block d) None of the mentioned View Answer Answer:a Explanation:With the help of RTTI, We can get the information about the data type at the runtime. 2. Which operators are part of RTTI? a) dynamic_cast() b) typeid c) Both a & b d) None of the mentioned View Answer Answer:c Explanation:The dynamic_cast<> operation and typeid operator in C++ are part of RTTI.
. What is meant by type_info? a) Used to hold the type information returned by the typeid operator b) Used to hold the type information returned by the dynamic_cast c) Used to hold the type information returned by the static cast d) None of the mentioned View Answer Answer:a Explanation:None. 10. At which time does the static_cast can be applied? a) Compile-time construct b) Runtime construct c) Both a & b d) None of the mentioned View Answer Answer:a
1. How many access specifiers are there in c++? a) 1 b) 2 c) 3 d) 4 View Answer Answer:c Explanation:There are three access specifiers in c++. They are public, Private and Protected. 2. What of the following describes protected access specifier? a) The variable is visible only outside inside the block b) The variable is visible everywhere c) The variable is visible to its block and to it’s derived class d) None of the mentioned View Answer Answer:c

Part - 2 Cpp programming Solved MCQ

  • 1.
    C++ Programming Questions Usefulfor all Companies Interviews, UGC-NET, GATE EXAM PART- 2
  • 2.
    . What isthe output of this program? 1.#include 2.using namespace std; 3.void duplicate (int& a, int& b, int& c) 4.{ 5.a *= 2; 6.b *= 2; 7.c *= 2; 8.} 9.int main () 10.{ 11.int x = 1, y = 3, z = 7; 12.duplicate (x, y, z); 13.cout << x << y << z; 14.return 0; 15.} a) 1468 b) 2812 c) 2614 d) none of the mentioned View Answer Answer:c
  • 3.
    . What isthe use of functor? a) It makes the object “callable” like a function. b) It makes the class “callable” like a function. c) It makes the attribute “callable” like a function. d) none of the mentioned View Answer Answer:a Pick out the correct option. a) References automatically dereference without needing an extra character. b) References automatically dereference with an extra character. c) Reference will not dereference d) none of the mentioned View Answer Answer:a
  • 4.
    1. Which isused to tell the computer that where a pointer is pointing to? a) dereference b) reference c) heap operations d) none of the mentioned View Answer Answer:a Explanation:None. 2. Which is used to do the dereferencing? a) pointer without asterix b) value without asterix c) pointer with asterix d) value with asterix View Answer Answer:c
  • 5.
    4. What isthe output of this program? 1.#include <iostream> 2.using namespace std; 3.int main() 4.{ 5.int a, b; 6.int* c; 7.c = &a; 8.a = 200; 9.b = 200; 10.*c = 100; 11.b = *c; 12.cout << *c << " " << b; 13.return 0; 14.} a) 100 200 b) 100 0 c) 200 200 d) 100 100 View Answer Answer:d
  • 6.
    5. What isthe output of this program? 1.#include <iostream> 2.using namespace std; 3.int main() 4.{ 5.int x; 6.int *p; 7.x = 5; 8.p = &x; 9.cout << *p; 10.return 0; 11.} a) 5 b) 10 c) memory address d) none of the mentioned View Answer Answer:a
  • 7.
    7. What isthe output of this program? 1.#include <iostream> 2.using namespace std; 3.int main() 4.{ 5.int x = 9; 6.int* p = &x; 7.cout << sizeof(p); 8.return 0; 9.} a) 4 b) 2 c) Depends on compiler d) none of the mentioned View Answer Answer:c
  • 8.
    1. Which operatorworks only with integer variables? a) increment b) decrement c) both a & b d) None of the mentioned View Answer Answer:c Explanation:None. 2. How many types are there in increment/decrement operator? a) 1 b) 2 c) 3 d) 4 View Answer Answer:b
  • 9.
    3. Pick outthe correct statement. a) Increment operator ++ adds 1 to its operand b) Increment operator ++ adds 2 to its operand c) Decrement operator ++ subtracts 1 to its operand d) None of the mentioned View Answer Answer:a Which symbol is used to create multiple inheritance? [A] Dot 0% [B] Comma 0% [C] Dollar 0% [D] None of the mentioned 0% Answer: B. Comma
  • 10.
    9. What doesthe dereference operator will return? a) rvalue equivalent to the value at the pointer address. b) lvalue equivalent to the value at the pointer address. c) it will return nothing d) none of the mentioned View Answer Answer:b Explanation:It operates on a pointer variable, and returns an l-value equivalent to the value at the pointer address. 10. Pick out the correct statement. a) The NULL pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to NULL. b) The NULL pointer dereference occurs where a pointer that is expected to be a valid address but instead is equal to memory address. c) both a & b d) none of the mentioned View Answer Answer:a
  • 11.
    4. What isthe output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int a = 21; 6.int c ; 7.c = a++; 8.cout << c; 9.return 0; 10.} a) 21 b) 22 c) 23 d) 20 View Answer Answer:a
  • 12.
    . What isthe output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int x = 5, y = 5; 6.cout << ++x << --y << endl; 7.return 0; 8.} a) 55 b) 64 c) 46 d) 45 View Answer Answer:b
  • 13.
    1. How manytypes of representation are in string? a) 1 b) 2 c) 3 d) 4 View Answer Answer:b 2. What is the header file for the string class? a) #include<ios> b) #include<str> c) #include<string> d) None of the mentioned View Answer Answer:c
  • 14.
    3. Which isused to return the number of characters in the string? a) length b) size c) both a & b d) None of the mentioned View Answer Answer:c
  • 15.
    9. Pick outthe correct statement a) Preincrement is faster than postincrement. b) postincrement is faster than preincrement. c) Both a & b d) None of the mentioned View Answer Answer:a Explanation:Because preincrement take one byte instruction & post increment takes two byte instruction. 10. Which concepts does the preincrement uses? a) call by value b) call by reference c) queue d) None of the mentioned View Answer Answer:b
  • 16.
    7. What isthe output of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int x = 5, y = 5, z; 6.x = ++x; y = --y; 7.z = x + ++x; 8.cout << z; 9.return 0; 10.} a) 11 b) 12 c) 13 d) 14 View Answer Answer:d
  • 17.
    What is theoutput of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int x = 5, y = 5, z; 6.x = ++x; y = --y; 7.z = x++ + y--; 8.cout << z; 9.return 0; 10.} a) 10 b) 11 c) 9 d) 12 View Answer Answer:a
  • 18.
    What is theoutput of this program? 1.#include <stdio.h> 2.using namespace std; 3.int main() 4.{ 5.int num1 = 5; 6.int num2 = 3; 7.int num3 = 2; 8.num1 = num2++; 9.num2 = --num3; 10.cout << num1 << num2 << num3; 11.return 0; 12.} a) 532 b) 235 c) 312 d) 311 View Answer Answer:d
  • 19.
    . Which methoddo we use to append more than one character at a time? a) append b) operator+= c) data d) both a & b View Answer Answer:d . Which is also called as abstract class? a) virtual function b) pure virtual function c) derived class d) None of the mentioned View Answer Answer:b
  • 20.
    1. Which classis used to design the base class? a) abstract class b) derived class c) base class d) None of the mentioned View Answer Answer:a Explanation:None. 2. Which is used to create a pure virtual function ? a) $ b) =0 c) & d) ! View Answer Answer:b
  • 21.
    What is theoutput of this program? 1.#include <iostream> 2.#include <string> 3.using namespace std; 4.int main () 5.{ 6.string str ("microsoft"); 7.string::reverse_iterator r; 8.for (r = str.rbegin() ; r < str.rend(); r++ ) 9.cout << *r; 10.return 0; 11.} a) microsoft b) micro c) tfosorcim d) tfos View Answer Answer:c
  • 22.
    8. What ismeant by pure virtual function? a) Function which does not have definition of its own. b) Function which does have definition of its own. c) Function which does not have any return type. d) None of the mentioned View Answer Answer:a Explanation:As the name itself implies, it have to depend on other class only. 9. Pick out the correct option. a) We cannot make an instance of an abstract base class b) We can make an instance of an abstract base class c) Both a & b d) None of the mentioned View Answer Answer:a Explanation:None.
  • 23.
    10. Where doesthe abstract class is used? a) base class only b) derived class c) both a & b d) None of the mentioned View Answer Answer:a 3. To which type of class, We can apply RTTI? a) Encapsulation b) Polymorphic c) Derived d) None of the mentioned View Answer Answer:b
  • 24.
    1. What isthe Run-Time Type Information? a) Information about an object’s datatype at runtime b) Information about the variables c) Information about the given block d) None of the mentioned View Answer Answer:a Explanation:With the help of RTTI, We can get the information about the data type at the runtime. 2. Which operators are part of RTTI? a) dynamic_cast() b) typeid c) Both a & b d) None of the mentioned View Answer Answer:c Explanation:The dynamic_cast<> operation and typeid operator in C++ are part of RTTI.
  • 25.
    . What ismeant by type_info? a) Used to hold the type information returned by the typeid operator b) Used to hold the type information returned by the dynamic_cast c) Used to hold the type information returned by the static cast d) None of the mentioned View Answer Answer:a Explanation:None. 10. At which time does the static_cast can be applied? a) Compile-time construct b) Runtime construct c) Both a & b d) None of the mentioned View Answer Answer:a
  • 26.
    1. How manyaccess specifiers are there in c++? a) 1 b) 2 c) 3 d) 4 View Answer Answer:c Explanation:There are three access specifiers in c++. They are public, Private and Protected. 2. What of the following describes protected access specifier? a) The variable is visible only outside inside the block b) The variable is visible everywhere c) The variable is visible to its block and to it’s derived class d) None of the mentioned View Answer Answer:c