Friday 18 November 2011

Predict the output or error(s) for the following:

void main()

{

int a, *pa, &ra;


pa = &a;


ra = a;


cout <<"a="<<a <<"*pa="<<*pa <<"ra"<<ra ;


}

Answer :

Compiler Error: 'ra',reference must be initialized


Explanation :

Pointers are different from references. One of the main differences is that the pointers can be both initialized and assigned, whereas references can only be initialized. So this code issues an error.

3 comments: