Question discussion

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

1167Medium 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[] = {1, 2, 3};
    int *p = a;
    (*p)++;
    p++;
    *p += 5;
    printf("%d %d %d", a[0], a[1], a[2]);
    return 0;
}
  • A2 2 8
  • B1 7 3
  • C2 8 3
  • D2 7 3
Correct answer: D

Explanation

(*p)++ makes a[0] = 2; p++ moves to a[1], and *p += 5 makes a[1] = 7; a[2] is unchanged.

Discussion 0

Nobody has replied yet. Start the discussion!