Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
int main()

{

char * A[] = {"C", "C++", "JAVA", "PHP"};
char **B[] = {A+2, A+1, A+3, A}, ***C;
C = B;
++C;
printf("%s", *(*C+1)+1);
return 0;
}

What I have tried:

not able to solve the question because of confusion i am getting answer as 'c++' but answer is 'AVA'
Posted
Updated 10-Feb-16 3:13am
v2
Comments
ZurdoDev 10-Feb-16 9:16am    
Follow the pointers.
Member 12284012 10-Feb-16 9:20am    
sir i want you to please explain the output of the program
ZurdoDev 10-Feb-16 9:37am    
I know, that's the title of your post.

I don't know what it is because I haven't run it. But this is clearly an example of understanding pointers.
Krunal Rohit 10-Feb-16 9:20am    
Or ask your teacher.

-KR

This is your homework, and we don't do your homework. And in this case it's a good thing!
This is an exercise in understanding pointers - and they are seriously important, so if you don't work it out for yourself you won't learn it properly.

So start with a blank sheet of paper, and a pencil.
Draw the A array and what it points to.
Now draw the B array, and work out what that contains, and draw in the "points to" lines.
Now do the same For C, and follow the code through, working out what value is referring to what at any particular time.
It's all pretty obvious if you look at it step by step.
Give it a try!
 
Share this answer
 
Run the code and insert some diagnostic printfs or operator >>s in to see what the intermediate values are. So with the first load of declarations you could do something like:

char * A[] = {"C", "C++", "JAVA", "PHP"};
for( auto t: A ) std::cout << t << std::endl;


Rinse and repeat for the subsequent lines and break that horrible, final expression up into manageable chunks.

If you do all that you will find the answer is "AVA".

Please don't write code like this in real life though. There are generally better ways of representing this sort of thing in C++.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900