Download presentation
Presentation is loading. Please wait.
1
Visit for more Learning Resources
Buy book Online - Visit for more Learning Resources
3
Array Definition : Array is a collection of similar data-type. Arrays can be created from any of the C data- types int, float, and char. So an integer array can only hold integer values and cannot hold values other than integer. There are basically two types of an array: 1. One dimensional array. 2. Two dimensional array. Buy book Online -
4
Single / One Dimension Arrays
Syntax : datatype name_of_array [size] ; Type of the array Name of the Size specify how many i.e int,char,float array elements will be in array Example : int marks[30] ; Buy book Online -
5
Example : One Dimension Arrays
#include <stdio.h> #include<conio.h> Output: int main() { Enter Array Element 1 int x[10]; printf(“Enter Array Elements”) 2 3 for(i=0;i<10;i++) { 4 2 scanf(" %d ", &x[i] ); initialization. // run time 3 } 23 34 } 12 34 getch(); return 0; }
6
Two Dimension Arrays int marks[30][30] ;
Syntax : datatype name_of_array [size][size] ; Type of the array Name of the Number Number i.e int,char,float array of rows of rows Example : int marks[30][30] ; Buy book Online -
7
Example : Two Dimension Arrays
#include<stdio.h> #include<conio.h> int main() { int array[2][2] = { 1,2 , 3,4 Output: } ; //two dimensional array declaration Array contents are: int i=0,j=0; Array[0][0]=1 printf(“\nArray contents are͗”) ; Array[0][1]=2 Array[0][0]=3 Array[0][0]=4 for(i=0;i<=1;i++) //Outer for loop to count number of rows { for(j=0;j<=1;j++) //Inner for loop to count number of rows { printf(“array*%d+*%d+=%d\t”, i,j,array[i][j]); //Displaying values at location ith row and jth column } printf(“\n”); } getch(); return 0; IcebreakersPublications.com }
8
String char name [30] ; Char name_of_array [size] ; Syntax :
Character Array Name of Array Size specify how many elements will be in array Example : char name [30] ; Buy book Online -
9
Example : String #include<stdio.h> #include<conio.h>
int main() { char string*30+=“Hello world”; int i=0; Output: String is Hello world printf(“\nString is %s”,string); //printing string using %s getch(); return 0; } Buy book Online -
10
For more detail contact us
End of chapter For more detail contact us
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.