Monday, October 11, 2010

Software Engg: Introduction to Programming:Array

Lecture Number 01
Topic : ARRAY
 
Array is a Collection of similar data elements places contiguously in memory. You may find it inconvenient to give each one a unique name. Suppose you find the average marks of five subjects of one student. Same variable but different subscripts or index numbers like other variables array needs to be defined so the compiler will know what kind of array and how large an array we want.

Int tem [7];
 
Here int specifies the type of variable, just as it does with simple variable and tem is name of variable. [7] is however new. An array uses a single identifier, together with an integer index, to create one variable that can hold many values. An array is created the same as a “normal” variable, but with the addition of square brackets indicating the size of the array. Each value in an array is accessed using the identifier and a valid index in square brackets. Each value in the array is called an element, and the identifier by itself resolves to the address of where the array is in memory. An array has a fixed number of elements based on its creation. The elements are ALWAYS numbered from 0 to 1 less than the array’s size. Referencing an element outside of the created bounds is possible but not recommended. An array has a fixed number of elements based on its creation. The elements are ALWAYS numbered from 0 to 1 less than the array’s size. Referencing an element outside of the created bounds is possible but not recommended. 

Over View of Arrays


Arrays store many values but have only one identifier. The array identifier represents the memory location of where the array begins.
The Array Element Operator []


The Array Element Operator is used to reference a specific array element. The expression inside the Array Element must resolve to type int. This value is known as an index. The value of the index can be any number, but care should be taken that the index falls within the bounds of the array. The bounds of an array are defined as 0 to 1 less than the size of the array.




Initializing Array


An array is initialized using a code block containing comma-delimited values which match in position the elements in the array. If there are values in the initialization block, but not enough to fill the array, all the elements in the array without values are initialized to 0 in the case of float or int, and NULL in the case of char. If there are values in the initialization block, an explicit size for the array does not need to be specified, only an empty Array Element Operator. C will count the values and size the array for you








     

         
 

No comments:

Post a Comment