C - Pointers - Discussion

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

 



Q.

What will be output if you will execute following code?

#include
int main(){
static char *s[3]={"math","phy","che"};
typedef char *( *ppp)[3];
static ppp p1=&s,p2=&s,p3=&s;
char * (*(*array[3]))[3]={&p1,&p2,&p3};
char * (*(*(*ptr)[3]))[3]=&array;
p2+=1;
p3+=2;
printf("%s",(***ptr[0])[2]);
return 0;

A. math B. phy
C. che D. math che

Answer: Option C
Explaination:

Here ptr: is pointer to array of pointer to string.P1, p2, p3: are pointers to array of string.array[3]: is array which contain pointer to array of string.As we know p[i]=*(p+i)

(***ptr[0])[2]=(*(***ptr+0))[2]=(***ptr)[2]
=(***(&array))[2] //ptr=&array
=(**array)[2] //From rule *&p=p
=(**(&p1))[2] //array=&p1
=(*p1)[2]
=(*&s)[2] //p1=&s
=s[2]="che"



Discussion

Your Comments Goes here...
NameDiscussion