edited by
4,232 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;

}
edited by

3 Answers

Best answer
13 votes
13 votes

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

Related questions

2 votes
2 votes
1 answer
1
1 votes
1 votes
1 answer
2
Na462 asked Jan 8, 2019
1,431 views
#include <stdio.h>main (){unsigned x = -10;int X = 20;if (X x) printf ("Hello");else{ printf ("%d",x); printf ("Jello"); }}
7 votes
7 votes
3 answers
3
Parshu gate asked Nov 20, 2017
773 views
What is the output of the following program?#include<stdio.h int main() { int array[]={10, 20, 30, 40}; printf(“%d”, -2[array]); return 0; }$-60$$-30$$60$Garbage valu...
3 votes
3 votes
1 answer
4
Parshu gate asked Nov 13, 2017
1,404 views
main( ){int n[3][3] = {2, 4, 3,6, 8, 5,3, 5, 1} ;printf ( "\n%d %d %d", *n, n[3][3], n ) ;}