in Programming in C edited by
4,224 views
2 votes
2 votes
char *c[] = {"GeksQuiz", "MCQ", "TEST", "QUIZ"};

char **cp[] = {c+3, c+2, c+1, c};

char ***cpp = cp;

int main()
{
    printf("%s ", **++cpp);
    
    printf("%s ", *--*++cpp+3);
    
    printf("%s ", *cpp[-2]+3);
    
    printf("%s ", cpp[-1][-1]+1);
    
    return 0;

}
in Programming in C edited by
4.2k views

3 Answers

13 votes
13 votes
Best answer

code:

#include <stdio.h>

char *c[] = {"GeksQuiz","MCQ","TEST","QUIZ"};
char **cp[] = {c+3,c+2,c+1,c};
char ***cpp = cp;

int main(int argc, char const *argv[]) {

	printf("%s ",**++cpp);					// *(*(++cpp))	
	printf("%s ",*--*++cpp + 3);		// *(--(*(++cpp))) + 3
	printf("%s ",*cpp[-2] + 3); 		// *(*(cpp - 2)) + 3
	printf("%s ",cpp[-1][-1] + 1); 	// *(*(cpp - 1) - 1) + 1

	return 0;
}

Before main(): assumed pointer size 4 bytes and char size 1 byte

Now,

The following precedence rules will be used.

And ptr = ptr + x,   will set ptr to   ptr + x*sizeof(*ptr).

First printf:

Second printf:

Third printf:

Fourth printf:

Similar QS

selected by
by

4 Comments

Wonderful explanation...
1
1
awesome explanation !!
0
0
What if we had  printf("%c" ,***++cpp+2);, then what would have been the output ??
0
0
ksQuiz
0
0
3 votes
3 votes

op: TEST sQuiz Z CQ

by
0 votes
0 votes

OUTPUT : TEST, sQuiz,Z,CQ. for complete solution visit this link https://drive.google.com/open?id=0B9FSROwjRRdqcTlqNTBLQnhQQ28

Related questions