I was wondering if there is a shorthand way to initialise a 2D or 3D array in C similar to the following syntax:
int array[1024] = {[0 ... 1023] = 5};
I was wondering if there is a shorthand way to initialise a 2D or 3D array in C similar to the following syntax:
int array[1024] = {[0 ... 1023] = 5};
The initialization you use isn't standard C, it's a GCC extension (Designated Initializers).
To initialize a 3d array, use:
int array[10][10][10] = {[0 ... 9] [0 ... 9] [0 ... 9] = 42};
Demo.