Practice mode C Language

What is printed by this C code: int a = {1, 2}; printf(“%d”, a);?

Correct answer B. 0

Explanation

When an array has an initialiser list shorter than the array, the remaining elements are initialised as if they had static storage duration, meaning they become zero. So a is {1, 2, 0, 0, 0} and a[3] is 0. Only an array declared with no initialiser at all would contain indeterminate values. This rule is why int a[100] = {0}; zeroes an entire array.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.