edited by
2,098 views
1 votes
1 votes
#include<stdio.h>
int main()
{
   char *s[] = {"ice","green","cone","please"};
   char **ptr[] = {s+3,s+2,s+1,s};
   char ***p = ptr;
   
   printf("%s\n",**++p);
   
   printf("%s\n",*--*++p + 3);
   
   printf("%s\n",*p[-2]+3);
   
   printf("%s\n",p[-1][-1] + 1);
   
    
   return 0;
}

Please anyone explain this especially last printf statement.
edited by

3 Answers

1 votes
1 votes

answer should be green of second  printf

0 votes
0 votes

S

1000 2000 3000 4000
ice green cone please

ptr

100 101 102 103
4000 3000 2000 1000

p

10 20 30 40
100 101 102 103

1.$**++p=*\left ( *\left (p+1 \right ) \right )=*\left ( *\left ( 20 \right ) \right )=*\left ( 101 \right )=3000$=value at 3000 is "cone"

2.$*--*++p+3=*\left ( --\left ( *\left ( ++p \right ) \right ) \right )+3$

$=*\left (--\left ( * \left ( 30\right )\right ) \right )+3$

$=*\left ( --\left(102\right ) \right )+3$ //from now 102  pointing to 3000

$=*\left ( 101 \right )+3=3000+3=3003=$will print "e"

3.$*p\left [ -2 \right ]+3=*\left ( *\left ( p-2 \right ) \right )+3=*\left ( *\left ( 10 \right ) \right )+3=*\left ( 100 ) \right )+3=4003$=will print value at address 1000="ase"

Now pic is

S

1000 2000 3000 4000
ice green cone please

ptr

100 101 102 103
4000 3000 3000 1000

                                                              p

10 20 30 40
100 101 102 103

means here p pointing to value at address 30 and address 102 pointing to 3000 too

4.$p\left [ -1 \right ]\left [ -1 \right ]+1$

Now p is pointing to "cone"

$p\left [ -1 \right ]\left [ -1 \right ]$ will print 1 row back of it.i.e. "green"

$=*\left ( 2000 \right )+1=2000+1=2001$=it will print   "reen"

edited by
0 votes
0 votes

I think this should be the answers printed by printf

Related questions

0 votes
0 votes
1 answer
1
Debargha Mitra Roy asked 2 days ago
42 views
#include <stdio.h int main() { int a[3] = {1, 3, 5, 7, 9, 11}; int *ptr = a[0]; ptr += sizeof(int); printf("%d", *ptr); return 0; }(Assume size of int to be $2$ bytes.)T...
0 votes
0 votes
2 answers
3
Debargha Mitra Roy asked Apr 10
100 views
What is the output of the below code?#include <stdio.h void main() { static int var = 5; printf("%d ", var ); if (var) main(); }a. 1 2 3 4 5b. 1c. 5 4 3 2 1d. Error
1 votes
1 votes
1 answer
4
SSR17 asked Feb 29
251 views
#include <stdio.h int main() { int i = -1; int x = (unsigned char)i; printf("%d", x); return 0; }output is 255 , but please explain how