Question:

What is the output of the following C code?

#include <stdio.h>
void func(int arr[]) {
 sizeof(arr) == sizeof(int) * 5 ? printf("True\n") : printf("False\n");
}
int main() {
  int arr[5] = {0};
  func(arr);
  return 0;
}

Show Hint

An array parameter decays to a pointer, so sizeof gives the pointer size.
Updated On: Jul 2, 2026
  • False
  • True
  • Compilation error
  • Syntax error
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Notice where sizeof is used. Inside func, the parameter written as int arr[] is not really an array. In C, an array parameter decays into a pointer.

Step 2: So sizeof(arr) inside func is the size of a pointer, typically 8 bytes on a 64-bit machine (or 4 bytes on 32-bit). It is not the size of the whole array.

Step 3: The right side sizeof(int) * 5 is \(4 \times 5 = 20\) bytes.

Step 4: Compare. Pointer size (8 or 4) is not equal to 20, so the condition is false.

Step 5: The ternary picks the false branch and prints False. The answer is False (option A).
Was this answer helpful?
0
0