An array is derived data type which can store similar type of data in sequence memory location. Data may be primitive type i.e int, char, float, double…
Example of array declaration:
int a[5];
char a[5];
float a[5];
long double a[5];
char * a[5];
int (a[])();
double ** a[5];
Array is useful when:
(a) We have to store large number of data of similar type.:
void main(){
int a=1;
int b=2;
int c=5;
int d=7;
int e=8;
int f=0;
int g=11;
int h=5;
int i=90;
int avg;
avg=(a+b+c+d+e+f+g+h+i)/9;
printf("%d",avg);
}
If we use array then the same program will written as;
void main(){
int a[ ]={1,2,5,7,8,0,11,5,50};
int i,avg;
for(int i=0;i<12;i++){
avg=avg+a[i];
}
printf("%d",avg/9);
}
Advantage of using array:
1. An array provides single name for many variables of same data type.
2. Array is used in data structure like. implementation of stack Queue, Tree etc.
|
|||
C - Overview | |||
C - Basic Syntax | |||
C - Data Types | |||
C - Variables | |||
C - Constants | |||
C - Storage Classes | |||
C - Operators | |||
C - Decision Making | |||
C - Loops | |||
C - Functions | |||
C - Scope Rules | |||
C - Arrays | |||
C - Pointers | |||
C - Strings | |||
C - Structures | |||
C - Unions | |||
C - Bit Fields | |||
C - Typedef | |||
C - Input & Output | |||
C - File I/O | |||
C - Preprocessors | |||
C - Header Files | |||
C - Type Casting | |||
C - Error Handling | |||
C - Recursion | |||
C - Variable Arguments | |||
C - Memory Management | |||
C - Command Line Arguments |
Thursday, 22 August 2013
Home »
C language
» Arrays in c
Arrays in c
Related Posts:
Pointers in c A pointer is an address. Instead of a variable, it is a pointer to a variable which is stored somewhere in the memory of the program. Let examine… Read More
Operators in C An operator is a symbol that instruct the compiler to perform specific mathematical or logical operation. C language has following type of operators: C Programming • Arithmetic Operators • … Read More
Loops in C This is an attempt at explaining the loops in C .It is not complete, just the basics. C Programming Loop is a construct which execute a set of statements certain number of times… Read More
Storage Classes in c A storage class in C defines the scope (visibility) and life-time of a variables and/or a functions .These specifiers precede the type that they modify. There are some storage classes, which are used in a C Pr… Read More
Constant and Literals in c The constants refer to fixed values that the program may not change during its execution. These values are also called literals. C Programming Constants can be of any of the data types like an integer … Read More
0 comments:
Post a Comment