Question discussion

Assume a 4-byte int and an 8-byte pointer. What is the output of the following C program?#include void f(int a[]) { printf("%zu ", sizeof(a…

1560Medium DSSSB TGT Computer Science 0 replies 1 views
0

Assume a 4-byte int and an 8-byte pointer. What is the output of the following C program?

#include <stdio.h>
void f(int a[]) { printf("%zu ", sizeof(a)); }
int main() {
    int arr[10];
    printf("%zu ", sizeof(arr));
    f(arr);
    return 0;
}
  • A40 40
  • B40 8
  • C10 10
  • D10 8
Correct answer: B

Explanation

In main, sizeof(arr) is 10 × 4 = 40 bytes, but inside f the array parameter has decayed to a pointer, so sizeof(a) is 8.

Discussion 0

Nobody has replied yet. Start the discussion!