Question discussion

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

2136Medium 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[5] = {1, 2, 3};
    printf("%d %d %d", a[4], (int)(sizeof a / sizeof a[0]), a[0] + a[3]);
    return 0;
}
  • A0 5 1
  • B0 3 1
  • Cundefined 5 1
  • D0 5 4
Correct answer: A

Explanation

The elements that are not given an initialiser are set to 0, so a[4] = 0 and a[3] = 0; the array still has 5 elements, and a[0] + a[3] = 1.

Discussion 0

Nobody has replied yet. Start the discussion!