DO NOT MISS

Ads

Saturday, 27 August 2016

One Dimensional Array in C-Language



A group of items can be given one variable name using only index such as a variable is known as single dimensional array. Single dimensional arrays the elements are represented one or two index of memory bytes.

(or)

A list of items can be given one variable name using only one subscript a such a variable is called a single sub scripted variable or One dimensional array. 



1. One Dimensional Arrays :- 

Collection of values with similar datatype using only one subscription is known as a One dimensional Array. 

Assigning the values to an One Dimensional Array :- 
There are two ways to assigning the values to an Array. 

1. Static time ( or ) Compile time 
2. Dynamic time ( or ) Run time 

1. Static time ( or ) Compile time:- 
In static time we can give the values to an Array at the time of compiling the program in two ways. 

1. One Dimensional Array initialization 
2. One Dimensional Array assignment 

1. One Dimensional Array initialization :- 
Assigning the values to an Array at the time of Variable declaration is known as a Variable initialization. 

Ex 1:- 


int a[5]={1,2,3,4,5}; 




Ex 2:-

int a[5]={10,15,30};


Ex 3:-
int a[5]={5,34,67,12,4,9,23,87};
It's Variable initialization is Error.

Ex 4:-
int a[5]={0};

2. One Dimensional Array Assignment :- 
Assigning the values to an Array after the Variable declaration is known as a Variable Assignment. 

Ex :- 

int a[5]; 

a[0]=1; 

a[1]=2; 

a[2]=3; 

a[3]=4; 

a[4]=5;


Displaying an Array values :-
By using the printf() we can display an Array values in two ways.

1. Without using loops.
2. With using loops.


1. Without using loops :-

Ex :-
int a[5];
printf("%d",a[0]);
printf("%d",a[1]);
printf("%d",a[2]);
printf("%d",a[3]);
printf("%d",a[4]);

2. With using loops :-

Ex:-
int a[5];
for(i=0;i<=size-1;i++)
printf("%d",a[i]);
  


2. Dynamic time :-

In Static time the values are can not be changed while running the program.
But if we want to give the values to Variable alternatively we should use the fallowing function scanf () .

scanf() :-
By using this function we can give the values to an Array Dynamically two ways.
1. Without using loops.
2. With using loops.

1. Without using loops :-
Ex :-
int a[5];
scanf("%d",&a[0]);
scanf("%d",&a[1]);
scanf("%d",&a[2]);
scanf("%d",&a[3]);
scanf("%d",&a[4]);

2. With using loops :-
Ex :-
int a[5];
for(i=0;i<=size-1;i++)
scanf("%d",&a[i]);



_____________________________________
_______________________________________________________________________________



Greataims

 
Copyright © 2016 Computersadda. Designed by @ Computersadda Team - Published By Greataims