Friday, July 31, 2009

Which of the statements below is true of int n =5, *p=&n;?

a. p is a pointer initialized to point to n.


b. p is a pointer initialized to the value of 5


c. n and p are both pointer variables


d. the declaration contains a syntax error

Which of the statements below is true of int n =5, *p=%26amp;n;?
Hi !





The right answer is "a. p is a pointer initialized to point to n."


Lets substantiate this statement!





Here I'm presenting you a simple program to reveal the fact !





void main()


{


int n = 5 , *p = %26amp;n;





printf("%d\n" , *p);


printf("%u %u " , %26amp;n , p);


}





Sample results obtained from this program


5





65524 65524


Let the address of 'n' is 65524 and p is a pointer initialized to point to n.





Its clear from the above results thats because p holds the address of n .





Thanks and Regards !


Prince M. Premnath
Reply:I think the answer must be A. The '*' symbol following the variable name is a pointer. when the %26amp; symbol is used before n, this means the address of n. This must be the pointer p is point to n.


No comments:

Post a Comment