C - Pointers - Discussion

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

 



Q.

What will be output if you will execute following code?

#include
int * function();
int main(){
auto int *x;
int *(*ptr)();
ptr=&function;
x=(*ptr)();
printf("%d",*x);
return 0;
}
int *function(){
static int a=10;
return &a;
}

A. 2 B. 4
C. 10 D. a

Answer: Option C
Explaination:

Here function is function whose parameter is void data type and return type is pointer to int data type.

x=(*ptr)()
=> x=(*&functyion)() //ptr=&function
=> x=function() //From rule *&p=p
=> x=&a
So, *x = *&a = a =10



Discussion

Your Comments Goes here...
NameDiscussion