ProgrammingHardTCS NQT · Infosys

Assume a pointer is 8 bytes and int is 4 bytes. What is printed?

Assume a pointer is 8 bytes and int is 4 bytes. What is printed?
#include <stdio.h>
void f(int v[]) {
    printf("%zu ", sizeof v);
}
int main(void) {
    int a[7];
    printf("%zu ", sizeof a / sizeof a[0]);
    f(a);
}
  1. A. 7 28
  2. B. 28 8
  3. C. 7 8
  4. D. 7 4

Correct answer: C. 7 8

Inside main, sizeof a / sizeof a[0] counts the 7 elements. The parameter int v[] is really an int *, so sizeof v is the pointer size of 8.

More C Programming questions

Exams that ask this topic