?
What will be the output of following program code?
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;
}
#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;
}
Answer & Solution
Correct Answer:
Option
C
x[i] is equivalent to *(x + i),
so (buf + 1)[5] is *(buf + 1 + 5), i.e. buf[6].
Join the Discussion
Login to post a comment or share your explanation.
LoginIt is just a variable name.
char buf{1,2,3,4,5,6,7,9,8}
p=buf[6]
printf(%d,p)
what is output of above program...??
Because in the program you write (buf+1)[5]
And in your suggestion you say that *(but+1)[5]
Meance the meaning is change because of astrik(*)
Meaning