Genesis Insoft The name you can TRUST
twitterlogo facebooklogo
Home  |  Contact Us |  Careers
C++ Question Bank / FAQs

This is a mock Exam for the C++ programmers. It is created by Genesis InSoft Limited (admin@genesisinsoft.com) and may be freely distributed so long as it is unmodified. Please email us if you have any corrections or comments.

Question 1

Which of the following statements is true?

  1. A constant member function does allow changes to any data members in the class
  2. A static member functions allows access to non-static data
  3. The size of the object is the sum of size of all non-static data
  4. The size of a struct variable is the sum of size of all static and all non-static data

Answer to Question 1

Question 2

What is the output of the following?

    #include
   
    void main()
    {
        int x = 20;
        int &t = x;
        x = 50;
        cout << x << " " << t;    
    }

  1. 20 50
  2. 50 20
  3. 50 50 
  4. None of the above

Answer to Question 2

Question 3

Friend function adds flexibility to the language, but they are controversial

  1. Because it goes against the rule of data encapsulation
  2. Because it can access a class's private data
  3. Both A and B
  4. None of the above

Answer to Question 3

Question 4

Which of the following is true about a destructor?

  1. Destructor like a constructor can accept arguments
  2. Destructor can be overloaded
  3. Destructor function is the same name as a class which is preceded by the tilde character
  4. Destructor return type is void

Answer to Question 4

Question 5

The prototype of output operator in the class "test" is as follows

  1. friend ostream & operator << (ostream &, test &)
  2. ostream & operator << (ostream &, test &)
  3. friend ostream & operator << (test &)
  4. friend ostream & operator << (ostream &)

Answer to Question 5

Question 6

Which of the following statements is false?

  1. Friend functions take one argument more than a member function
  2. Operator overloading allows us to create new operators
  3. Static member functions can access only static data
  4. A constant cannot be changed

Answer to Question 6

Question 7

Which of the following statements is true?

  1. We cannot overload operator new and operator delete
  2. Each instance of a class has a different copy of static data
  3. We need to define in every class a constructor and destructor
  4. class istream extends class ios

Answer to Question 7

Question 8

What is the output of the following?

    #include <iostream.h>

    int add(int, int = 5, int = 10);

    void main() {
        cout << add(10) << " " << add(10, 20) << " " << add(10, 20, 30);
    }

    int add(int a, int b, int c)
    {
        return a + b + c;
    }

  1. compilation error
  2. 25 40 60
  3. 15 30 60
  4. 20 40 60

Answer to Question 8

Question 9

To turn overloading off, which of the statements is used?

  1. extern "C"
  2. static "C"
  3. Register "C"
  4. off "C"

Answer to Question 9

Question 10

The keywords related to exception handling are?

  1. test, catch
  2. try, throw, catch
  3. namespace, catch
  4. try, finally

Answer to Question 10

Question 11

Genericity is a technique to

  1. Defining software components that have more than one interpretation depending on the data type of parameter. 
  2. Which allows the extension of the functionality of the existing software components. 
  3. To derive a class from more than one base class. 
  4. Of creating new data types that are well suited to an application.

Answer to Question 11

Question 12

Comments are

  1. Integral part of the program and they do nothing 
  2. Integral part of the program and they help in coding and maintenance 
  3. Are not part of the program 
  4. Are not part of the program and they slow down the execution speed

Answer to Question 12

Question 13

C++ does not support the following feature?

  1. Multiple inheritance
  2. Polymorphism
  3. Operator overloading
  4. Automatic memory management

Answer to Question 13

Question 14

What is the output of the program?

    #include <iostream.h>
    char *buf1 = "Genesis", *buf2 = "InSoft";
    
    void main()
    {
        char* const q=buf1;
        *q='x';
        cout << *q;
    }

  1. x
  2. xenesis
  3. l-value specifies constant object
  4. None of the above

Answer to Question 14

Question 15

What happens when new operator is called?

  1. It invokes operator new, then invokes the constructor and then does type casting
  2. It invokes the constructor, calls operator new and then does type casting
  3. It invokes operator new and then invokes the constructor
  4. It invokes the constructor and then does type casting

Answer to Question 15

Question 16

Which keyword violates data encapsulation?

  1. Public 
  2. Virtual 
  3. Friend
  4. Protected

Answer to Question 16

Question 17

Which of the following is not true about destructor?

  1. Destructor can be overloaded
  2. A destructor class member function is typically used to return dynamically allocated memory
  3. A destructor function has the same name as the class in which it is defined preceded by the tilde character
  4. A destructor does not have any return type

Answer to Question 17

Question 18

What is the output of the program?

    #include <iostream.h>

    void main()
    {
        int val = 5;
        int &val1 = val;
        int &val2;
        cout << val1;
    }

  1. 5
  2. val2 - references must be initialized
  3. Address of variable val is printed
  4. None of the above

Answer to Question 18

Question 19

What happens when delete operator is called?

  1. It invokes operator delete and then invokes the destructor if any
  2. It invokes the destructor if any and then calls operator delete
  3. It invokes operator delete
  4. It invokes the destructor if any

Answer to Question 19

Question 20

Which of the following are true about default arguments?

  1. Default arguments must be the last argument
  2. A default argument cannot be redefined in later declarations even if the redefinition is identical to the original
  3. Additional default arguments can be added by later declarations
  4. All of the above

Answer to Question 20

Answers

Answer 1 - C

Back to question 1

Answer 2 - C

Back to question 2

Answer 3 - C

Back to question 3

Answer 4 - C

Back to question 4

Answer 5 - A

Back to question 5

Answer 6 - B

Back to question 6

Answer 7 - D

Back to question 7

Answer 8 - B

Back to question 8

Answer 9 - A

Back to question 9

Answer 10 - B

Back to question 10

Answer 11 - A

Back to question 11

Answer 12 - B

Back to question 12

Answer 13 - D

Back to question 13

Answer 14 - A

Back to question 14

Answer 15 - A

Back to question 15

Answer 16 - C

Back to question 16

Answer 17 - A

Back to question 17

Answer 18 - B

Back to question 18

Answer 19 - A

Back to question 19

Answer 20 - D

Back to question 20

Copyright © 2000 to 2011 Genesis InSoft Limited. All Rights Reserved.