Web Development

General discussion


some problem with pointers in c++

By monukaushal ·
int x=10,*p,*q;
cout<<"Contents of q is"<<*q;
my question is y the answer is 0 as the value must be an address.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by PubServant In reply to some problem with pointer ...

You have dereferenced q in the cout statement. By using *q, you have asked that the value at storage location q be printed. The contents may be 0 as you have stated, or it more typically is a residual value at that storage location since variables aren't initialized when they are declared.

If you want the address to be printed, use q without the "*" in the cout statement as in the following statement.

cout << "The address of q is " << q;

Related Discussions

Related Forums