edited by
2,019 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
SSR17 asked Feb 29
204 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
2 votes
2 votes
1 answer
2
rupamsardar asked Aug 30, 2023
466 views
#include <stdio.h int f(int x) { if(x%2==0) { return f(f(x-1)); } else return (x++); } int main() { printf("%d",f(12)); ret...
5 votes
5 votes
2 answers
3
saurabh0709 asked Aug 1, 2023
1,136 views
What will be the output of the following code? _______ #include <stdio.h int main(){ char val=250; int ans; ans= val+ !val + ~val + ++val; printf("%d", ans); return 0; }
2 votes
2 votes
1 answer
4