some problem with pointers in c++
main()
{
int x=10,*p,*q;
p=&x;
q=p+6;
cout<<"Contents of q is"<<*q;
}
my question is y the answer is 0 as the value must be an address.
Web Development
main()
{
int x=10,*p,*q;
p=&x;
q=p+6;
cout<<"Contents of q is"<<*q;
}
my question is y the answer is 0 as the value must be an address.
by pubservant
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;
This discussion is closed to new replies.
Sort by Trending