This section contains more frequently asked Programming In C++ Objective Questions Answers in the various University Level and Competitive Examinations.
1. What is the error in the following code? class t { virtual void print(); }
- No error.
- Function print() should be declared as static.
- Function print() should be defined.
- Class t should contain data members.
A. No error.
2. What will be the output of following program? #include void main() { float x; x=(float)9/2; cout x; }
- 4.5
- 4.0
- 4
- 5
A. 4.5
3. A white space is :
- blank space
- new line
- tab
- all of the above
D. all of the above
4. The following can be declared as friend in a class
- an object
- a class
- a public data member
- a private data member
B. a class
5. What would be the output of the following? #include void main() { char *ptr=“abcd” char ch; ch = ++*ptr++; cout ch; }
- a
- b
- c
- d
B. b
6. A copy constructor takes
- no argument
- one argument
- two arguments
- arbitrary no. of arguments
B. one argument
7. Overloading a postfix increment operator by means of a member function takes
- no argument
- one argument
- two arguments
- three arguments
A. no argument
8. Which of the following ways are legal to access a class data member using this pointer?
- this.x
- *this.x
- *(this.x)
- (*this).x
D. (*this).x
9. If we store the address of a derived class object into a variable whose type is a pointer to the base class, then the object, when accessed using this pointer.
- continues to act like a derived class object.
- Continues to act like a derived class object if virtual functions are called.
- Acts like a base class object.
- Acts like a base class, if virtual functions are called.
B. Continues to act like a derived class object if virtual functions are called.
10. Which of the following declarations are illegal?
- void *ptr;
- char *str = “hello”;
- char str = “hello”;
- const *int p1;
C. char str = “hello”;