Question Details

No question body available.

Tags

c++ arrays c static

Answers (1)

July 10, 2026 Score: 0 Rep: 45,100 Quality: Low Completeness: 70%

If you remove all decorations, the example would be a single line, that is valid in C and invalid in C++:

static int a[];
  • static int a[] is static int a[1] in C if it's not defined with a complete array type in the same translation unit (Clang compiler warns warning: array 'a' assumed to have one element)
  • static int a[] is invalid in C++ (error: storage size of 'a' isn't known)

BTW the last code snippet in the question is invalid and exhibits UB in C.

The answer to your main question

Why might the answers be different?

Because C and C++ are distinct programming languages.