© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

13. What is a Null object?


Ans:

It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.

Ex 1: Find the output of the following program
class complex{
            double re;
            double im;
public:
            complex() : re(0),im(0) {}
            complex(double n) { re=n,im=n;};
            complex(int m,int n) { re=m,im=n;}
            void print() { cout<
};
 
void main(){
            complex c3;
            double i=5;
            c3 = i;
            c3.print();
}
 
Ans:
            5,5

Explanation:

            Though no operator= function taking complex, double is defined, the double on the rhs is converted into a temporary object using the single argument constructor taking double and assigned to the lvalue.

SLogix Student Projects
bottom