Question discussion

What will be the output of following program code?#include int main(void){ char p; char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8}; p = (buf + 1)[5…

279434Medium 1 reply 529 views
0
What will be the output of following program code?#include <stdio.h>int main(void){ char p; char buf[10] = {1, 2, 3, 4, 5, 6, 9, 8}; p = (buf + 1)[5]; printf("%d", p); return 0;}
  • A5
  • B6
  • C9
  • DError
  • ENone of the above
Correct answer: C

Discussion 1

0
CCommunity
9

x[i] is equivalent to *(x + i),
so (buf + 1)[5] is *(buf + 1 + 5), i.e. buf[6].