Loading, please wait...

A to Z Full Forms and Acronyms

Array declaration in C Programming

Aug 30, 2019 array, one-dimension array , 2543 Views
In this article we will discuss about array declaration.

ARRAY DECLARATION

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[5]; 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[10];
float real[10];
long num [5];

when we declare a variable, for example:

int x;

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.

X=4;

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 [3][3]; 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]; . 

A to Z Full Forms and Acronyms