Академический Документы
Профессиональный Документы
Культура Документы
Arrays Structures of related data items Static entity same size throughout program Group of consecutive memory locations Same name and type First element at position 0
c c [0] [1] c c [2] [3] c [4] c c [5] [6] c [7] c c [8] c[9] [10] c [11]
Array Declaration
When declaring arrays, specify Name Type of array Number of elements arrayType arrayName[ numberOfElements ]; Examples: int c[ 10 ]; float myArray[ 3284 ]; Declaring multiple arrays of same type Format similar to regular variables Example: int b[ 100 ], x[ 27 ];
Array Initialization
int n[ 5 ] = { 1, 2, 3, 4, 5 }; int n[ 5 ] = { 0 } //All elements 0 C arrays have no bounds checking
5 initializers, therefore 5 element array Enter the elements of array //&a for(int i=0;i<=n-1;i++) { scanf(%d,&a[i]); &a[0]; } scanf(%d,&a[0]); scanf(%d,&a[1]); scanf(%d,&a[2]); scanf(%d,&a[3]);
Array Printing/accessing
Array elements are like normal variables c[ 0 ] = 3; printf( "%d", c[ 0 ] ); Elements are for(int i=0;i<=3;i++) { printf(%d,a[i]); }
; ; ; ;
programs
a.1 Accept elements from user n display a.2 Avg and sum, a.3 Count of even and odd nos. a.4 Finding largest/minimum of user entered no. a.9 Displaying fibonacci series using array a.5 searching an element a.6 Sorting using bubble sort a.7 searching using function a.8 bubble sort using function
Address of the first element passed to pointer variable indicated with brackets
int b[2][3];
declares the name of the array to be b the type of the array elements to be int the dimension to be 2 (two pairs of brackets []) the number of elements or size to be 2*3 = 6