ExamVeda
Login
Home
This question belongs to C Program Arrays And Strings
Arrays and Strings
?

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;
}

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].

Examveda
Question posted by Examveda
Community

Join the Discussion

10 Comments
Monu Dixit
Monu Dixit 6 years ago
data type of p is character but while printing 'p' given is %d so how it will execute
Nripesh Kumar
Nripesh Kumar 6 years ago
those who are confused with buf.
It is just a variable name.
Sakshi Jadhav
Sakshi Jadhav 8 years ago
char p,
char buf{1,2,3,4,5,6,7,9,8}
p=buf[6]
printf(%d,p)
what is output of above program...??
Monisha Moni
Monisha Moni 8 years ago
Explain me in brief about buf concept
Suman Manna
Suman Manna 9 years ago
What is but?
Examveda
Examveda 9 years ago
Read the explanation.
Shubham Kothavade
Shubham Kothavade 9 years ago
How are you do these process
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(*)
Onkar Pawar
Onkar Pawar 9 years ago
what are but?
Meaning
Anuradha Chintamani
Anuradha Chintamani 10 years ago
How buf[6] is 9.....??
Sopan Jadhav
Sopan Jadhav 10 years ago
What are the buf?