void fun ()
{
int i;
int a[]=
{
[0]=3,
[1]=5
};
}
Does the above way of a[] array assignment is supported in c language. if yes which c version.
i compiled above code with gcc it works fine.
but i never saw this kind of assignment before.
Declaring Arrays:typeName variableName[size]; This declares an array with the specified size, named variableName, of type typeName. The array is indexed from 0 to size-1. The size (in brackets) must be an integer literal or a constant variable.
Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To create an array, define the data type (like int ) and specify the name of the array followed by square brackets [].
But, the elements in an array can be explicitly initialized to specific values when it is declared, by enclosing those initial values in braces {}. For example: int foo [5] = { 16, 2, 77, 40, 12071 };
Array Declaration by Initializing ElementsAn array can be initialized at the time of its declaration. In this method of array declaration, the compiler will allocate an array of size equal to the number of the array elements. The following syntax can be used to declare and initialize an array at the same time.
This is GCC extension to C89, part of standard in C99, called 'Designated initializer'.
See http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Designated-Inits.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With