Single dimensional array
A list of items can be given one variable name using only one subscript and such a variable is called a single-subscripted variable or a one dimensional array.
Declaration
Like any other variable, array must be declared before they are you used. The general form of Array declaration is
Syntax:-
Data_type array_name[size of array]; |
---|
Ex:-int num[10];
>> the data type specifies the type of an element that you will be contained in the array such as int, float ,or char.
>>The size indicate the maximum number of elements that can be stored inside the array.
>> The size of Array should be constant value.
Example:-
float ht[20];
->>declares the height to be an array containing 20 real elements.
int group[15];
->>declares the group as an array to contain a maximum of 15 integers constant .
char ch[12];
->>declares the ch as a character array (string) variable that can hold a maximum of 12 characters.
Ex:-int num[10];
Memory allocation:-
Single-dimensional array are always allocated contiguous blocks of memory.
This implies that all the elements in an array are always stored next to each other.
memory=no.of bytes × size |
---|
Memory allocation in array |
- Value->num[0]=3
- Value->num[1]=6
- Value->num[2]=9
Comments