'array value at an index for which value hasn't been defined
in this code:
#include <stdio.h>
int main(void)
{
int a[2][3] = {{1,2},{4,5,6}};
printf("%d\n",a[0][2]);
return 0;
}
The output is 0 - since the array wasn't initialized, is this output a result of some undefined behaviour?
Solution 1:[1]
The array was initialised. You’re defining a two-dimensional array that consists of two arrays of three integers each. For the first of these two you only give two values, and by default the missing one is initialised as zero, so your full array is {{1, 2, 0}, {4, 5, 6}. a[0][2] will give you that zero.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Schnitte |
