How to declare an array in c









To declare any array in c you must have to know three things:
1. Name of the array
2. Data type of array
3. Size and dimension of the array.

Name of array: It can be any valid c identifier.
Valid array name are:
array
_abc_
Array32
 Invalid array name are:
__TIME__
32Array
pascal

To know more about valid identifier, go through following link.
Identifiers naming rule.

Data type of array: It can be any valid data type of c language like int, char, double, pointer etc.

Size and dimension of the array: Array can have single or multiple dimensions. Each dimension has its own size.

Examples of declaration of different type of arrays:

//Array of integer numbers of size five:
int array[5];

//Array of double numbers of size two:
double array[2];

//Two dimension array characters
char world[3][5];

//Array of pointer to float of size six
float *arr[6];

//Array of pointer to structure Abc of size six
struct Abc *arr[6];

//Array of pointer to function printf of size ten
int(*arr[10])(char const *, …);









No comments: