Machine-translated by Google. Questions are authored in English.
Top

Discussion

What will be the output of the program ?

#include <stdio.h>

int main()
{
    static char mess[6][30] = {"Don't walk in front of me...", 
                               "I may not follow;", 
                               "Don't walk behind me...", 
                               "Just walk beside me...", 
                               "And be my friend." };

    printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9));
    return 0;
}

 

  • A.t, t
  • B.k, k
  • C.n, k
  • D.m, f

Answer: B

Correct answer: k, k

mess[2] is "Don't walk behind me...", and index 9 counts D-o-n-'-t-space-w-a-l-k - giving k. The second expression, *(*(mess+2)+9), is the same thing written in pointer form, since mess[i] is *(mess+i). So both print k.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.