Ad Code

Responsive Advertisement

array in C language.

First we understtod that why we need the array?


When the user used the primitive data type there have only one value stored but, if user want to use many variable than it will be difficulty to used the veriable name.

Like :  int s,b,c,d,e,f,g,h,i,j;

in the above you can see that there are 10 veriable it is difficulty  to remember the veriable name so, the reduce the difficulties C language provide us derived data type . In this data type only one veriable can used as a many veriable. So in the place of derived data type we used the array.

A array can used to stored many values in one veribale. User does not write 10 veriable just used the array and the array work as a 10 veriable.


And the array is start with 0


SYNTEX :  data type array_namep[scope];

like : int a[10];

a[0]
a[1]
a[2]
a[3]
a[4]
a[5]
a[6]
a[7]
a[8]
a[9]
a[\o]



in there the array sized  10 maens 10 veriable.if the user used the primitive data type than the used the 10 veriable but in dirived data type a one veriable used as a 10 veriable. An din the last in this arrya the NULL value is stored in every array .it data type is integer.



First we learn the integer array : in the integer array , the array is called it is a integer array .like int a[5] it is a integer array .because it data type is integer type. And here 5 veriable is  used and the memory allocation is 10 byte ( one veriable=2byte ) for window and (one veriable=4 byte) for ubuntu.Here we used the ubuntu .so, the memory allocation is 20 byte.


Than character array : first if we don't about the character data type than first learn the character data type.

In the character data type if, the user primitive data type than the veriable is stored only one character means a to z . but the problem is that if the user want to stored the name(string), than it is complusory to use the derived data type.

SYNTEX : character a[10];
in this veriable only 10 character is stored.
So, this is the array which is used to as a many veriable.

Exapmle :
#include<stdio.h>
void main()
{
int a[2];
a[0]=4;
a[1]=7;

printf(“%d”,a[0]);
printf(“\n%d”,a[1]);
}
out put: 4
5



type of array ther are three type of array

1) one – Dimension array
2) two - Dimension array
3) multi -Dimension array




1)one dimension array : in this array the array like a[] in one sized. It same as a above.

2) two dimension array : in two dimension array the array like a[][] the array is a two tiype.this type of array is used to make a matrix program and other type of program.

Like : int a[5][5];
this is the two dimension array.

Example :
#include<stdio.h>
void main()
{
int i,j,a[2][2];

printf(“Enter a number”);
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
{
scanf(“%d”,&a[i][j]);
}
}

printf(“\nEntered the numbers\n”);

for(i=0; i,2; i++)
{
for(j=0; j<2; j++)
{
printf(“%d”,a[i][j]);
}
}
printf(“\n”);
}

out put : Enter a number
1234
Entered the number
1 2
3 4

❮ Previous                                                      Next ❯

Post a Comment

0 Comments