- A pointer is
the data type of an address variable
- a variable for storing addresses
- a special type of integer variable
- a special type of operator
- The declaration statement int* p1, p2 ;
- declares two pointer variables p1 and p2
declares two integer variables p1 and p2
- declares p1 as a pointer variable and p2 as an integer variable
- is illegal because of blank space between * and p1
- The statement int * p ; can be interpreted as
- the variable whose address is stored in p is an integer
- the variable pointed to by p is an integer
p points to an integer
- All the above
- For the statement p = *m; which of the following statements is TRUE?
The value of m is assigned to p
- The value of the variable pointed to by m is assigned to p
- p is a pointer variable
- Address of m is assigned to p
- Identify the error in the following code segment
- int *ptr, m = 100; // line 1
- cout << *ptr; //line 2
- Declaring ptr and m in one line is wrong
In line 2, *ptr should be written as &ptr
- The address of m should be assigned to ptr before it is accessed
- No error
- Compile-time polymorphism is accomplished by using
- function overloading
Operator overloading
- a and b
- neither a nor b
- The mechanism of using virtual functions to achieve polymorphism is known as
- run-time polymorphism
- dynamic binding
late binding
- all the above
- consider the following class definition: If x is an object of Test and ptr is a pointer to x, then which one of the following statements can correctly invoke the function show ( )?
- class Test
- {
- public : void show (void) {cout <<”Test”;}
- };
- x.show ( ) ;
- ptr -> show ( ) ;
- (*ptr). show ( );
- All of the above
- If x is a private data member of a class, then it is legal to assign a value to x inside a member function using
- x = 100;
- this ->x = 100;
- (*this).x = 100;
- all the above
- The statement return * this ;
inside a member function of a class returns ?
- a copy of the object that invoked the function
- address of the member function
- address of this pointer
- None of the above
- Which of the following statements is FALSE?
Address of a derived class object can be assigned to a base class pointer
- Treating the base class object as a derived class object is wrong
- Address of a base class object can be assigned to a derived class pointer
- A base class pointer cannot be used to access all the members of the derived class
- In C++, virtual functions are used to
- create functions that can never be accessed
- to make a base class abstract
- to create an array of base class pointers that can point to different functions
- enable the use of the same function call to invoke functions from different classes.
- Which of the following statements is TRUE about virtual functions?
- A constructor cannot be a virtual function
- A virtual function in the base class must be defined, even though it may not be used
They cannot be declared static
- All the above
A pure virtual function is a virtual function that
- makes the class to be abstract
- is used in derived classes
- is used to transform the base class into a virtual base class
- takes no argument and returns nothing
- Which of the following statements is TRUE?
- All virtual functions in an abstract base class must be declared as pure virtual functions
- A class is made abstract by declaring it virtual
- A derived class cannot contain a pure virtual function
- If a base class declares a pure virtual function, all derived classes must define the function.
Answers:
- a variable for storing addresses
- declares p1 as a pointer variable and p2 as an integer variable
- All the above
- The value of the variable pointed to by m is assigned to p
- The address of m should be assigned to ptr before it is accessed
- a and b
- all the above
- all the three
- all the above
- a copy of the object that invoked the function
- Treating the base class object as a derived class object is wrong
- enable the use of the same function call to invoke functions from different classes
- All the above
- makes the class to be abstract
- If a base class declares a pure virtual function, all derived classes must define the function
You must log in to post a comment.