What is the effect of 'int mat[3][3] = {0};' in C?

Enhance your programming skills with the RECF Programming Test. Features flashcards and multiple choice questions with hints and explanations. Prepare for success!

Multiple Choice

What is the effect of 'int mat[3][3] = {0};' in C?

Explanation:
In C, initializing a multi‑dimensional array with an incomplete initializer fills the unspecified elements with zeros. Here, the 3×3 int array has a single initializer, so the first element mat[0][0] gets 0 and all the remaining elements are zero-initialized as well. The result is a 3×3 matrix where every entry is 0. This is valid C code, and it does not produce ones or indeterminate values.

In C, initializing a multi‑dimensional array with an incomplete initializer fills the unspecified elements with zeros. Here, the 3×3 int array has a single initializer, so the first element mat[0][0] gets 0 and all the remaining elements are zero-initialized as well. The result is a 3×3 matrix where every entry is 0. This is valid C code, and it does not produce ones or indeterminate values.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy