You are on page 1of 9

C programming presentation

ARRAY
ARRAYS IN C

 Array in C can be defined as a method of clubbing multiple


entities of similar type into a larger group.
 An array is a variable that stores multiple variable of the same data
type which can be accessed individually and independently.
 A square bracket is linked in the end of the variable name to
convert the single value variable into an array.
Types of array in C

 Array is mainly divided into two main categories


1. Single dimensional array
2. Multi dimensional array
 Each can be further classified into int,double,float or char
arrays.
Single dimensional array

 A one-dimensional array (or single dimension array) is a


type of linear array.
 To create a single dimensional array a square bracket is
attached to the end of the vaiable name.
 Accessing its elements involves a single subscript
which can either represent a row or column index.
 Indexing starts with 0 which is the position of the first element
in the array.
Array with int double and float

 To store multiple values in an int double or float array the


syntax below is used.
Int variable_name[x] = {a,b,c,d};

Int age[3] = {20,18,34};


Double gpa[5] = {2.5,3.7,2.95,1.89};
float marks[4] = {32,6.4,20.3};
Cont…

 To access an individual element in an array


Printf(“%d”,age[0]);
RESULT : 20
Printf(“%f”,gpa[3]);
RESULT : 1.89
Printf(“%f”,marks[1]);
RESULT : 6.4
Character Array or Strings

 A set of character in an array in c is known as string .


 A string is enclosed by a double quotation.
 The syntax of a string is shown below.

Char variable_name[x] = “characters”;

Char my_name = “Ahmed”;


Printf(“%s”,my_name[]);
RESULT : Ahmed
Modifying arrays

 Like any other variable array can be modified and given a new
value wholly or individually.
Int numbers[10] = {4,6,8,1};

Int numbers[]=23;

Int numbers[4] = {3,7,90,150,16};


THANK YOU

You might also like