ProgrammingHardGATE CS

What is printed? Assume int is 4 bytes and pointers are 8 bytes.

What is printed? Assume int is 4 bytes and pointers are 8 bytes.
#include <stdio.h>
void f(int a[10]) {
    printf("%zu ", sizeof a);
}
int main(void) {
    int a[10];
    f(a);
    printf("%zu %zu", sizeof a, sizeof &a[0]);
    return 0;
}
  1. A. 8 40 8
  2. B. 8 40 4
  3. C. 40 40 8
  4. D. 40 40 40

Correct answer: A. 8 40 8

A parameter declared as int a[10] is really int *a, so sizeof a inside f is 8. In main, a is a true array: sizeof a = 40, and &a[0] is a pointer: 8.

More C Programming questions

Exams that ask this topic