Published on: 12th Nov 2010 | Last Updated on: 24th Nov 2011
Array :
Array is a collection of homogenous data stored under unique name. The values in an array is called as 'elements of an array.' These elements are accessed by numbers called as 'subscripts or index numbers.' Arrays may be of any variable type.
Array is also called as 'subscripted variable.'
Types of an Array :
Single / One Dimensional Array :
The array which is used to represent and store data in a linear form is called as 'single or one dimensional array.'
Syntax: <data-type> <array_name> [size]; Example: int a[3] = {2, 3, 5}; char ch[20] = "TechnoExam" ; float stax[3] = {5003.23, 1940.32, 123.20} ; Total Size (in Bytes): total size = length of array * size of data type
In above example, a is an array of type integer which has storage size of 3 elements. The total size would be 3 * 2 = 6 bytes.
* Memory Allocation :
Fig : Memory allocation for one dimensional array
Program :
/* Program to demonstrate one dimensional array.
Creation Date : 10 Nov 2010 11:07:49 PM
Author :www.technoexam.com [Technowell, Sangli] */
#include <stdio.h> #include <conio.h> void main() { int a[3], i;; clrscr(); printf("\n\t Enter three numbers : "); for(i=0; i<3; i++) { scanf("%d", &a[i]); // read array } printf("\n\n\t Numbers are : "); for(i=0; i<3; i++) { printf("\t %d", a[i]); // print array } getch(); }
Output :
Enter three numbers : 9 4 6 Numbers are : 9 4 6_
Features :
- Array size should be positive number only.
- String array always terminates with null character ('\0').
- Array elements are countered from 0 to n-1.
- Useful for multiple reading of elements (numbers).
Disadvantages :
- There is no easy method to initialize large number of array elements.
- It is difficult to initialize selected elements.
Link this post on your Blog/Website :

