ArrayPresentation in C
ArrayPresentation in C
Arrays In C
By:-
Arush Swaroop
100101051
CS-C
Index
What are Arrays?
Types of Arrays
1-D Arrays
Recognising Arrays
Data Types of Arrays
Space Allocation
Assigning Values to Arrays
Multidimensional Arrays
What Are Arrays?
An Array is a systematic arrangement of objects, usually in rows and
columns.
It is a data structure.
The whole array bears a single name, and the individual items or elements
that are accessed by using an integer index .
Type of Arrays
1-Dimensional Array
2-Dimensional Array
3-Dimanesional Array
1-Dimensional Arrray
Example
int debts[10];
“int” is the Datatype.
“debts” is name of Array.
“10” is the Number of Elements in an Array.
Example . .
. .
X = debts[2];
debts[8] 5
(this will transfer the
value at index 2 of 8
debts array, i.e. 1 to debts[9]
the variable X)
Data Types of Arrays
Arrays can be of all datatypes that C allow.
Examples:-
int boo[4];
(an array to hold 4 ints)
char foo[4];
(an array to hold 4 chars)
Initialization of An Array
A single variable can be initialized as;
int debt = 2;
Array Initialization
#define NUM = 8;
int main(void)
{
int powers[NUM] = {1,2,4,6,8,16,32,64}; (ANSI only)
... }
What if we don’t initialize an Array
Designated Initialization
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;