ProgrammingHardProduct company OA

With 4-byte int, what is printed?

With 4-byte int, what is printed?
int n = 0;
int f(void) { n++; return 1; }
int main(void) {
    size_t s = sizeof(f());
    printf("%zu %d", s, n);
}
  1. A. 1 1
  2. B. 4 0
  3. C. 4 1
  4. D. 8 0

Correct answer: B. 4 0

sizeof only needs the type of its operand, and f() has type int, so the call is never made and n stays 0. (The one exception is a variable-length array, whose size must be computed at run time.)

More C Programming questions

Exams that ask this topic