C++ Quiz Questions Set 2

1) What is the out put?
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.

No comments:

Post a Comment