Data Structure-Array
Data Structure-Array
Kaustuv Bhattacharjee
University of Engineering & Management, Kolkata
Array-Introduction
• A collection of fixed size similar data elements
• Data elements have same data type
• Elements are stored in consecutive memory
locations
• Elements can be referenced by an index
(called subscript), which is an ordinal number
to identify and element of the array
• Example:
– int name[10];
– The above statement declares name is an array of
10 integer type elements.
– Array index starts from 0.
– Elements are stored as name[0], name[1], …,
name[9].
– 0,1,2,3,… are subscripts.
int i, marks[10];
for (i=0,i<10,i++)
scanf(“The array element at index ”%d” is:”%d, &i, &marks[i]);
The above code will access every data elements of the array and
will set the value to the one entered by user.
int i, marks[10];
for (i=0,i<10,i++)
scanf(“The array element at index ”%d” is:”%d, &i, &marks[i]);
int i, j, marks[14][5];
for (i=0,i<10,i++)
for (j=0,j<10,j++)
scanf(“The array elements are:”, &marks[i][j]);
The above code will access every data elements of the 2D array and
will set the value to the one entered by user
Answers:
1. (b) 2. (b) 3. (d) 4. (b) 5. (b) 6. (d)