C++ programming language
1. A friend function to a class, C cannot access
- private data members and member functions.
- public data members and member functions.
- protected data members and member functions.
- 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 _________
- call by name
- call by value
- call by reference
- call by value result
Correct answer: (B)
call by value
3. A pointer to the base class can hold address of
- only base class object
- only derived class object
- base class object as well as derived class object
- 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
- are removed from memory when not in use.
- permit data to be hidden from other classes.
- bring together all aspects of an entity in one place.
- 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
- there are no member functions.
- all members are public.
- cannot be used in inheritance hierarchy.
- it does have a this pointer.
Correct answer: (C)
cannot be used in inheritance hierarchy.
6. A variable defined within a block is visible
- from the point of definition onward in the program.
- from the point of definition onward in the function.
- from the point of definition onward in the block.
- throughout the function.
Correct answer: (C)
from the point of definition onward in the block.
7. A virtual class is the same as
- an abstract class
- a class with a virtual function
- a base class
- none of the above.
Correct answer: (D)
none of the above.
8. Additional information sent when an exception is thrown may be placed in
- the throw keyword.
- the function that caused the error.
- the catch block.
- 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?
- first letter
- entire string
- it is a syntax error
- last letter
Correct answer: (A)
first letter
10. Data members which are static
- cannot be assigned a value
- can only be used in static functions
- cannot be defined in a Union
- can be accessed outside the class
Correct answer: (B)
can only be used in static functions