What will be output of following program?
#include<stdio.h>
int main(){
int i = 5;
int *p;
p = &i;
printf(" %u %u", *&p , &*p);
return 0;
}
(A) 5 Address
(B) Address Address
(C) Address 5
(D) Compilation error
(E) None of above
________________________________________
Explanation:
Turbo C++ 3.0: Address Address
Turbo C ++4.5: Address Address
Linux GCC: Address Address
Visual C++: Address Address
Since * and & always cancel to each other.
i.e. *&a = a
so *&p = p which store address of integer i
&*p = &*(&i) //since p = &i
= &(*&i)
= &i
So second output is also address of i
No comments:
Post a Comment