C - Pointers - Discussion

You Are Here :: Home > C > Pointers - Discussion

 



Q.

What will be output of following c program?

#include
int main(){
int x=10;
int *ptr=&x; //statement one
int **temp=&ptr; //statement two
printf("%d %d %d".x.*ptr,**temp);
return 0;
}

A. 10 0 10 B. 0 10 10
C. 10 10 0 D. 10 10 10

Answer: Option D
Explaination:

As we know value of variable x is 10.

*ptr= *(&x) //from statement one
=*&x
=x //using cancellation rule
=10
**temp= **(&ptr)=*(*&ptr)=*ptr=*(&x)=*&x=x=10



Discussion

Your Comments Goes here...
NameDiscussion