0% found this document useful (0 votes)
6 views1 page

2: Partial Array Initilization:: How To Access The Elements of An Array?

Uploaded by

ramphere41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

2: Partial Array Initilization:: How To Access The Elements of An Array?

Uploaded by

ramphere41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

//error : Number of initial values are more than the size of array.

2 : Partial Array Initilization : partial array initialization is possible in C language. If the


number of values to be initialized is less than the size of the array, then the elements are
initialized in the order from 0th location. The remaining locations will be initialized to zero
automatically.

Ex : Consider the partial initilization

int a[5]={10,15};

Eventhough compiler allocates 5 memory locations, using this declaration


statement, the compiler initializes first two locations with 10 and 15, the next set of memory
locations are automatically initialized to zero.

The array a is partial initialization as

a[0] a[1] a[2] a[3] a[4]

10 15 0 0 0

1000 1002 1004 1006 1008

How to access the elements of an array?


You can access elements of an array by indices/index. You can use array subscript (or index) to
access any element stored in array. Subscript starts with 0, which means array_name[0] would be
used to access first element in an array.

In general array_name[n-1] can be used to access nth element of an array. where n is any integer
number.

Example

float mark[5];

Suppose you declared an array mark as above. The first element is mark[0], second element
is mark[1] and so on.

You might also like