Examveda
Examveda

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

A. 5

B. 6

C. 9

D. Error

E. None of the above

Answer: Option C

Solution(By Examveda Team)

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


This Question Belongs to C Program >> Arrays And Strings

Join The Discussion

Comments ( 10 )

  1. Monu Dixit
    Monu Dixit :
    3 years ago

    data type of p is character but while printing 'p' given is %d so how it will execute

  2. Nripesh Kumar
    Nripesh Kumar :
    3 years ago

    those who are confused with buf.
    It is just a variable name.

  3. Sakshi Jadhav
    Sakshi Jadhav :
    5 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...??

  4. Monisha Moni
    Monisha Moni :
    6 years ago

    Explain me in brief about buf concept

  5. Suman Manna
    Suman Manna :
    6 years ago

    What is but?

  6. Examveda
    Examveda :
    7 years ago

    Read the explanation.

  7. Shubham Kothavade
    Shubham Kothavade :
    7 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(*)

  8. Onkar Pawar
    Onkar Pawar :
    7 years ago

    what are but?
    Meaning

  9. Anuradha Chintamani
    Anuradha Chintamani :
    7 years ago

    How buf[6] is 9.....??

  10. Sopan Jadhav
    Sopan Jadhav :
    7 years ago

    What are the buf?

Related Questions on Arrays and Strings