one dimensional array

One dimensional array :

The elements of an integer array a [5] are stored in continuous memory location.It is assumed that the starting memory location is 2000.Each integer element requires 2 bytes. Hence subsequent element appears after gap of 2 locations.
The below table shows the locations of elements of an integers array.

                Integer datatypes and their memory locations
Elements
A[0]
A[1]
A[2]
A[3]
A[4]
Address
2000
2002
2004
2006
2008




Similarly,the elements of an arrays of any data type are stored in continuous memory location. The only difference is that number of locations are different for different datatypes.

/*An example illustrated below based on this point.*/
#include <stdio.h>
#include <conio.h>
main ( )
{
int i[10];
char c[10];
long l[10];
printf("The type 'int' requires %d Bytes ",sizeof(int));
printf("The type 'char' requires %d Bytes ",sizeof(char));
printf("The type 'long' requires %d Bytes ",sizeof(long));
printf("%d memory locations are reserved for ten 'int' elements",sizeof(i));
printf("%d memory locations are reserved for ten 'char' elements",sizeof(c));
printf("%d memory locations are reserved for ten 'long' elements",sizeof(l));
}

OUTPUT:
The type 'int' requires 2 Bytes
The type 'char' requires 1 Bytes
The type 'long' requires 4 Bytes
20 memory locations are reserved for ten 'int' elements
10 memory locations are reserved for ten 'char' elements
40 memory locations are reserved for ten 'long' elements

Explanation :
The sizeof ( ) function provides the size of the data type in bytes.In the above example int, char, &long type of data variables are supplied to this function which gives the results 2, 1,&4 bytes respectively . Required number of memory location for int , char and long will be 2,1,and 4. Memory location required for the array =argument of an array x sizeof [data type].
In the above example array int i [10] requires 20 memory locations since each element requires 2 memory locations. Memory requirement for various data types will be as given in the below table..

Data Type & Their Required Bytes
Data type
Memory requirement
Character
1byte
Integer
2bytes
Float
4bytes
Long
4bytes
Double
8bytes








Character array are called strings.there is a large difference between an integer array and a character array.In character array NULL ('\0') character is automatically added at the end,where as in integer or other types of array no NULL character is placed at the end.
Th NULL character acts as an end of the character array.By using this NULL character compiler detects the end of the character array.when a compiler reads the NULL character '\0' there is end of character array.

TIP :Details information about string will be in the string chapter...........