Array Presentation in C
Array Presentation in C
Arrays In C
1
2
It is used to store series of values of the same type, sequentially
The whole array bears a single name, and the individual items, or
elements, are accessed by using an integer index
e.g
int debts[10];//int is the datatype
//debts is name of array
//and 20 is the number of elements //contained in an
array
How the Compiler recognizes an Array?
X = debts[2]; . .
. .
/*this will transfer the
value at index 2 of 5
debts array, i.e. 1 to debts[8]
the variable X*/ 8
debts[9]
Data Types of Arrays
Array Initialization;
#define NUM = 8; /*constant, a good prog. practice*/
int main(void)
{
int powers[NUM] = {1,2,4,6,8,16,32,64}; /* ANSI only */
... }
Another way;
const int days[] = {31,28,31,30,31,30,31,31,30,31};
//compiler sets the number of items to 10 automatically
Designated Initialization;
Declaration;
int box[2][2];
int box[2][2][2]; //uptil 26 in Bloodshed DevC
Initialization;
Int box[2][2] = { {1, 2}, {3, 4} }; //two col and rows
Int box[2][2][2] = {
{ {1,2}, {3, 4} },
{ {5,6}, {7, 8} }
};
Passing Arrays to Function
#include <stdio.h>
int sum(int arr[]);
int main(void)
{
int i ;
int arr[4];
long answer;