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

What restrictions apply to reference variables?

  1. You cannot reference a reference variable (i.e. you cannot take its address)
  2. You cannot create arrays of references
  3. References are not allowed on bit fields
  4. All of the above

Answer to Question 1

Question 2

What is the output of the program?

    #include <iostream.h>

    struct Emp
    {
        int id;
        float basic;
        float cal_salary();
        void show_emp();
    };

    void main()
    {
        Emp e1;
        e1.basic = 5000.5;
        cout << e1.basic <<endl;
    }

  1. 5000
  2. 5000.5
  3. Error - as private data cannot be accessed
  4. None of the above

Answer to Question 2

Question 3

What is the output of the program?

    #include <iostream.h>
    class test
    {
        test()
        {
            cout << "constructor called" ;
        }
    };

    void main()
    {
        test a();
    }

  1. constructor called
  2. Error - constructor cannot be private
  3. no output is displayed
  4. None of the above

Answer to Question 3

Question 4

What is the output of the program?

    #include <iostream.h>
    class test
    { 
        int x;
        public:
            test(int y)
            {
                x = y;
            }

            int getX()
            {
                int x = 40;
                return this->x;
            }
    };

    void main()
    {
        test a(10);
        cout << a.getX();
    }

  1. Compilation error
  2. 10
  3. 40
  4. None of the above

Answer to Question 4

Question 5

What is the prototype of pre increment operator in class test?

  1. void operator ++ ();
  2. test operator ++ (int);
  3. void operator ++ (int);
  4. test operator ++ ();

Answer to Question 5

Question 6

What restrictions apply to extern "C"?

  1. You can specify extern "C" for only one instance of an overloaded function; all other instances of an overloaded function have C++ linkage
  2. You can only declare C functions as 'extern "C"
  3. You cannot declare a member function with extern "C"
  4. Both A and C

Answer to Question 6

Question 7

What is the output of the program?

    #include <iostream.h>

    void fun(int & a, int b)
    {
        a += 20;
        b += 30;
    }

    void main()
    {
        int x = 10, y = 50;
        fun(x, y);
        cout << x << " " << y ;
    }

  1. 30 80
  2. 10 50
  3. 30 50
  4. 10 80

Answer to Question 7

Question 8

What is the output of the following?

    #include <iostream.h>
    class test
    { 
        char x;
        static char c;
    };

    void main()
    {
        test a;
        cout << sizeof(a);
    }   

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

Answer to Question 8

Question 9

What is the signature of the output operator for class test?

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

Answer to Question 9

Question 10

What is the member function called in the statement "test b = a" shown below?

    void main()
    {
        test a(10);
        test b = a;
    }

  1. Assignment operator
  2. Constructor
  3. Copy constructor
  4. None of the above

Answer to Question 10

Question 11

A variable that is part of a class, yet is not part of an object of that class, is called a?

  1. Static member
  2. Friend member
  3. Constant member
  4. Non-static member

Answer to Question 11

Question 12

The only member functions that could be called for const objects would be?

  1. Constructors 
  2. Destructor 
  3. Const member functions
  4. All of the above

Answer to Question 12

Question 13

Which of the following type conversions is automatic?

  1. Conversion from built-in type to class type

  2. Conversion from class type to built-in type

  3. Conversion from one class type to another class type

  4. None of the above

Answer to Question 13

Question 14

Which keyword do we use if the data members of the class are to be modified even when it belongs to a constant object?

  1. mutable
  2. static
  3. const
  4. friend

Answer to Question 14

Question 15

Which condition should the conversion function from class type to built-in type satisfy?

  1. It must be a class member
  2. It must not specify a return type
  3. It must not have any arguments
  4. All of the above

Answer to Question 15

Question 16

We prefer initialization to assignment for the following reason?

  1. Const members can only be initialized
  2. Reference members can only be initialized
  3. To improve the efficiency, when a class contains a data member which is an object of another class
  4. All of the above

Answer to Question 16

Question 17

Which keyword specifies that those members are accessible only from member functions and friends of the class and its derived classes?

  1. private
  2. public
  3. protected
  4. All of the above

Answer to Question 17

Question 18

Which of the following statements is correct?

  1. When preceding the name of a base class, the protected keyword specifies that the public and protected members of the base class are protected members of the derived class
  2. Default access of a base class is private for classes
  3. Default access of a base class is public for structures
  4. All of the above

Answer to Question 18

Question 19

What is the output of the program?

    # include <iostream.h>

    union test {
        int x;
    };

    class uc : public test
    {
        int y;
    };

    main()
    {
        uc u;
        cout << sizeof(u);
    }

  1. 8
  2. 4
  3. union cannot be used as base class
  4. None of the above

Answer to Question 19

Question 20

Which of the following statements are true about static member functions?

  1. Cannot make use of this pointer
  2. Cannot access any non-static data
  3. Cannot be declared const
  4. All of the above

Answer to Question 20

Answers

Answer 1 - D

Back to question 1

Answer 2 - B

Back to question 2

Answer 3 - C

Back to question 3

Answer 4 - B

Back to question 4

Answer 5 - D

Back to question 5

Answer 6 - D

Back to question 6

Answer 7 - C

Back to question 7

Answer 8 - A

Back to question 8

Answer 9 - D

Back to question 9

Answer 10 - C

Back to question 10

Answer 11 - A

Back to question 11

Answer 12 - D

Back to question 12

Answer 13 - D

Back to question 13

Answer 14 - A

Back to question 14

Answer 15 - D

Back to question 15

Answer 16 - D

Back to question 16

Answer 17 - C

Back to question 17

Answer 18 - D

Back to question 18

Answer 19 - C

Back to question 19

Answer 20 - D

Back to question 20

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