Array is a collection of similar data type items. Arrays are used to store group of data of same datatype. Arrays can of any datatype. Arrays must have constant size. Continuous memory locations are used to store array. Array index always starts with 0.
Example for Arrays:
int a[5]; // integer array
char a[5]; // character(string) array
Types of Arrays:
# One Dimensional Array
# Two Dimensional Array
# Multi Dimensional Array
One Dimensional Array
Array declaration
int age [5];
Array initialization
int age[5]={0, 1, 2, 3, 4, 5};
Accessing array
age[0]; /*0_is_accessed*/
age[1]; /*1_is_accessed*/
age[2]; /*2_is_accessed*/
Two Dimensional Array
Two dimensional array is combination of rows n columns.
Array declaration
int arr[2][2];
Array initialization
int arr[2][2] = {{1,2}, {3,4}};
Accessing array
arr [0][0] = 1;
arr [0][1] = 2;
arr [1][0] = 3;
arr [1][1] = 4;
Multi Dimensional Array
C programming language allows programmer to create arrays of arrays known as multidimensional arrays.
For example:
float a[2][4][3];
Passing Array To Function
In C we can pass entire Arrays to functions as an argument.
For eg.
#include <stdio.h>
void display(int a)
{
int i;
for(i=0;i < 4;i++){
printf("%d",a[i]);
}
}
int main(){
int c[]={1,2,3,4};
display(c);
//Passing array to display.
return 0;
}
These are the Concept of C programming . We'll be glad if you share your valuable information with us regarding this topic, then it will be a golden opportunity for all of us to improve ourselves and know more. Comment below!!
Comments
Post a Comment