Array declaration in C Programming
Declaration of a one-dimensional array can be done with data type first, followed by the variable name and lastly, the array size is enclosed in square brackets. Array size should be integer constant and it must be greater than zero and data type should be valid C data type.
For example, the declaration of the one-dimensional array is as follow:
int a; it tells the compiler that ‘a’ is an integer type of an array and its size is five integers. The compiler reserve 2 bytes of memory for each integer array element, i.e. 10 bytes are reserved for storing five integers in the memory. In the same way, an array of different data types is declared as follows:
char ch; float real; long num ;
when we declare a variable, for example:
the variable x is declared and the memory location of two bytes is allocated to it and later a single value can be stored in it.
Every variable has a name, a value assigned to it and it is to be stored in memory location. Hence, from the above, we can say that only one value is assigned to a variable or stored.
The way, we declare a one-dimensional array in the same way and can also declare a two-dimensional array. A two-dimensional array is a table that contains rows and columns. For example, int a ; It informs the compiler that ‘a’ is an integer type of an array and its size is 9 integers. This array is a three-by-three matrix. Its details are given in the two-dimensional array and operations.
Similarly, one can declare the multi-dimensional array as follows:
data type array name [size1][size2][size3]---------[size4]; .