1,292 views
1 votes
1 votes

Consider the following C program segment:

#include <stdio.h>
main()
{
    static char*s[] = {"black","white","yellow","violet"};
    char **ptr[]={s+3,s+2,s+1,s},***p;
    p=ptr;
    ++P;
    printf("%s",*--*++p+3);
    
}

          

What will be printed by the program?

  • et
  • ite
  • ck
  • yellow

1 Answer

Best answer
3 votes
3 votes

++ p means p points to S+2
*(--(*(++P)))+3

++P : address of S+1
*(++P) : S+1
--(*(++P)) : S
*(--(*(++P))) : Address of 1st element of array i.e. Address of 'b'

*(--(*(++P))) + 3 : address of 'c'

now Print string starting from 'c' i.e. 'ck'

 

selected by

Related questions

0 votes
0 votes
1 answer
1
2 votes
2 votes
2 answers
3
atulcse asked Jan 15, 2022
698 views
Consider the following programint find (int n) { int a = 1; for (i = 1; i < = n; i ++) for (j = 1; j < = i; j++) for (k = 1; k <= j, k++) a = a + 1; ...
4 votes
4 votes
4 answers
4
manisha11 asked May 30, 2019
1,581 views
void fun(int *p) { int q = 10; p = &q; z } int main() { int r = 20; int *p = &r; fun(p); printf("%d", *p); return 0; }