Home / General Knowledge / Testing New :: Discussion

Discussion :: Testing New

  1. Determine Output:

    void 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);

    }

  2. A.

     te

    B.

     ow

    C.

     et

    D.

     ck

    View Answer

    Workspace

    Answer : Option D

    Explanation :

    In this problem we have an array of char pointers "s" pointing to start of 4 strings. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p holds the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated as follows: *++p causes gets value s+1 then the pre decrement is executed and we get s+1-1 = s which is pointing to the word "black". The indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position. Thus, the output is 'ck'.


Be The First To Comment