Question discussion

What is the output of the following C program?#include int main() { int a[] = {2, 4, 6, 8, 10}; int *p = a + 4; printf("%d %d %d", *p - *(p…

1558Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int a[] = {2, 4, 6, 8, 10};
    int *p = a + 4;
    printf("%d %d %d", *p - *(p - 3), (int)(p - a), *(a + *a));
    return 0;
}
  • A6 4 4
  • B6 4 6
  • C6 16 6
  • D8 4 6
Correct answer: B

Explanation

*p = 10 and *(p − 3) = a[1] = 4, giving 6; p − a counts elements, i.e. 4; and *(a + *a) = *(a + 2) = 6.

Discussion 0

Nobody has replied yet. Start the discussion!