ProgrammingModerateTCS NQT · Infosys

What is printed? Assume a pointer is 8 bytes and a char array of length 10 is passed to f.

What is printed? Assume a pointer is 8 bytes and a char array of length 10 is passed to f.
#include <stdio.h>
void f(char s[]) {
    printf("%zu", sizeof s);
}
int main(void) {
    char b[10];
    f(b);
}
  1. A. 10
  2. B. 9
  3. C. 1
  4. D. 8

Correct answer: D. 8

A parameter declared as char s[] is really a char *, so sizeof s is the pointer size, 8 bytes here. The array length 10 is not passed.

More C Programming questions

Exams that ask this topic