C - Pointers - Discussion

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

 



Q.

What will be output if you will execute following code?

#include
int main(){
char *array[4]={"c","c++","java","sql"};
char *(*ptr)[4]=&array;
printf("%s ",++(*ptr)[2]);
return 0;
}

A. c B. java
C. ava D. jav

Answer: Option C
Explaination:

ptr: It is pointer to array of string of size 4.

array[4]: It is an array and its content are string.
++(*ptr)[2]
=++(*&array)[2] //ptr=&array
=++array[2]
=++"java"
="ava" //Since ptr is character pointer so it
// will increment only one byte



Discussion

Your Comments Goes here...
NameDiscussion