( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
strings.ppt
1. INSTITUTE OF AERONAUTICAL ENGINEERING
(Autonomous)
Dundigal, Hyderabad- 500043
PROGRAMMING FOR PROBLEM SOLVING
USING C
Prepared By
K.Laxminarayanamma, Assistant Professor, IT Dept.
.
3. ARRAY
C Array is a collection of variables belongings to the same data type.
You can store group of data of same data type in an array.
• Array might be belonging to any of the data types
• Array size must be a constant value.
• Always, Contiguous (adjacent) memory locations are used to store
array elements in memory.
• It is a best practice to initialize an array to zero or null while
declaring, if we don’t assign any values to array.
4. TYPES OF C ARRAYS:
There are 2 types of C arrays. They are,
• One dimensional array
• Multi dimensional array
Two dimensional array
Three dimensional array
four dimensional array etc…
6. ONE DIMENSIONAL ARRAY
Integer array example:
int age [5];
int age[5]={0, 1, 2, 3, 4};
age[0]; /*0 is accessed*/
age[1]; /*1 is accessed*/
age[2]; /*2 is accessed*/
7. Character array example:
char str[10];
char str[10]={‘H’,‘a’,‘i’};
str[0]; /*H is accessed*/
str[1]; /*a is accessed*/
str[2]; /*i is accessed*/
8. EXAMPLE PROGRAM FOR ONE DIMENSIONAL ARRAY IN C:
#include<stdio.h>
int main()
{
int i;
int arr[5] = {10,20,30,40,50};
// declaring and Initializing array in C
//To initialize all array elements to 0, use int arr[5]={0};
/* Above array can be initialized as below also
arr[0] = 10; to
arr[4] = 50; */
for (i=0;i<5;i++)
{// Accessing each variableprintf("value of arr[%d] is %d n", i, arr[i]);}
}
9. Two dimensional array
• The two dimensional array in C language is represented in the form
of rows and columns, also known as matrix. It is also known as array
of arrays or list of arrays.
• The two dimensional, three dimensional or other dimensional arrays
are also known as multidimensional arrays.
10. Declaration of two dimensional Array in C
We can declare an array in the c language in the following way.
data_type array_name[size1][size2];
A simple example to declare two dimensional array is given below.
int twodimen[4][3];
Here, 4 is the row number and 3 is the column number.
11. Two dimensional array example in C
#include<stdio.h>
int main(){
int i=0,j=0;
int arr[4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};
//traversing 2D array
for(i=0;i<4;i++){
for(j=0;j<3;j++){
printf("arr[%d] [%d] = %d n",i,j,arr[i][j]);
}//end of j
}//end of i
return 0;
}