C++ programming language

1. A friend function to a class, C cannot access

  1. private data members and member functions.
  2. public data members and member functions.
  3. protected data members and member functions.
  4. the data members of the derived class of C.

Correct answer: (D)
the data members of the derived class of C.

2. A function call mechanism that passes arguments to a function by passing a copy of the values of the arguments is _________

  1. call by name
  2. call by value
  3. call by reference
  4. call by value result

Correct answer: (B)
call by value

3. A pointer to the base class can hold address of

  1. only base class object
  2. only derived class object
  3. base class object as well as derived class object
  4. None of the above

Correct answer: (C)
base class object as well as derived class object

4. A property which is not true for classes is that they

  1. are removed from memory when not in use.
  2. permit data to be hidden from other classes.
  3. bring together all aspects of an entity in one place.
  4. Can closely model objects in the real world.

Correct answer: (C)
bring together all aspects of an entity in one place.

5. A struct is the same as a class except that

  1. there are no member functions.
  2. all members are public.
  3. cannot be used in inheritance hierarchy.
  4. it does have a this pointer.

Correct answer: (C)
cannot be used in inheritance hierarchy.

6. A variable defined within a block is visible

  1. from the point of definition onward in the program.
  2. from the point of definition onward in the function.
  3. from the point of definition onward in the block.
  4. throughout the function.

Correct answer: (C)
from the point of definition onward in the block.

7. A virtual class is the same as

  1. an abstract class
  2. a class with a virtual function
  3. a base class
  4. none of the above.

Correct answer: (D)
none of the above.

8. Additional information sent when an exception is thrown may be placed in

  1. the throw keyword.
  2. the function that caused the error.
  3. the catch block.
  4. an object of the exception class.

Correct answer: (C)
the catch block.

9. Consider the following statements char *ptr; ptr = 'hello'; cout << *ptr; What will be printed?

  1. first letter
  2. entire string
  3. it is a syntax error
  4. last letter

Correct answer: (A)
first letter

10. Data members which are static

  1. cannot be assigned a value
  2. can only be used in static functions
  3. cannot be defined in a Union
  4. can be accessed outside the class

Correct answer: (B)
can only be used in static functions

Page 1 of 5