Introduction To Array:
*Array Is A Type Of Data Structure Which Store Collection of Data Of
Same Type.Which Can Be Integer Float Or Character.
*All arrays consist of contiguous memory locations.
*The lowest address corresponds to the first element and the highest
address to the last element.
Declaration Of Array:-
It Consist up of 3 part :-
1.Data Type
2.Array Name
3.Size Of Array
General Syntax:-
data_type Array_name[size_of_array];
For Example:-
int marks[20];
in example datatype of array is int and name is marks and size is 20.
* It Is Called Single Dimensional Array
* the Array Size Must be Integer And it
must be greater than zero.
Initialization Of Array:
*We initialize an array in C either one by one or using a single statement
as follows:
For Example:-
int marks[5]={95,96,97,98,99};
*The number of values between braces { } cannot be larger than the number of
elements that we declare for the array between square brackets [ ].
*All arrays have 0 as the index of their first element which is also called base
index and the last index of an array will be total size of the array minus 1.
Accessing Array Elements:-
We Use for loop from zero to less than array size.this is described in
below program:-
Example Program:-
#include <stdio.h>
int main ()
{
int a[8]; /* n is an array of 10 integers */
int i,j;
/* initialize elements of array n to 0 */
for (i=0; i<8; i++)
{
a[i] = i + 200; /* set element at location i to i+200 */
}
/* output each array element's value */
for (j=0; j<8; j++)
{
printf("Element[%d] = %d\n", j, a[j] );
}
return 0;
}
The Output Of Program Is:-
Element[0] = 200
Element[1] = 201
Element[2] = 202
Element[3] = 203
Element[4] = 204
Element[5] = 205
Element[6] = 206
Element[7] = 207
Types Of Array:-
1)One Dimensional Array
2)Two Dimensional Array
3)Multidimensional Array
This Will Describe In next Posts:-
-:PLEASE SHARE US:-
-:THANKS A LOT:-
*Array Is A Type Of Data Structure Which Store Collection of Data Of
Same Type.Which Can Be Integer Float Or Character.
*All arrays consist of contiguous memory locations.
*The lowest address corresponds to the first element and the highest
address to the last element.
Declaration Of Array:-
It Consist up of 3 part :-
1.Data Type
2.Array Name
3.Size Of Array
General Syntax:-
data_type Array_name[size_of_array];
For Example:-
int marks[20];
in example datatype of array is int and name is marks and size is 20.
* It Is Called Single Dimensional Array
* the Array Size Must be Integer And it
must be greater than zero.
Initialization Of Array:
*We initialize an array in C either one by one or using a single statement
as follows:
For Example:-
int marks[5]={95,96,97,98,99};
*The number of values between braces { } cannot be larger than the number of
elements that we declare for the array between square brackets [ ].
*All arrays have 0 as the index of their first element which is also called base
index and the last index of an array will be total size of the array minus 1.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAiOy-R6JtfqmzGs8NryQ-SOKssluvN2k6kvqchoDN4tiP6BEbraGThHc1wz0-5Ld6pZR9sA1oUigesm6T3U85kiOGHm0UU9X4-O_IL5t1ocJUyt_rVTguBkKHHFyJVmO-Zoewai6UwaY/s200/ar.jpg)
We Use for loop from zero to less than array size.this is described in
below program:-
Example Program:-
#include <stdio.h>
int main ()
{
int a[8]; /* n is an array of 10 integers */
int i,j;
/* initialize elements of array n to 0 */
for (i=0; i<8; i++)
{
a[i] = i + 200; /* set element at location i to i+200 */
}
/* output each array element's value */
for (j=0; j<8; j++)
{
printf("Element[%d] = %d\n", j, a[j] );
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6_gsE8I-PQEO-0vf9Ln6ECPSPYs4W3EVIWc9x5Uhz8x0xtjgpiyKBTDz_Nn1lL2HRNq6CJn3maGra5HGy_rBzY617Y4Eqi7WWEs0WZ0yhIsYb4WurCxJDAqf5phTSvcHuycy4TYml-GA/s320/ar1.jpg)
return 0;
}
The Output Of Program Is:-
Element[0] = 200
Element[1] = 201
Element[2] = 202
Element[3] = 203
Element[4] = 204
Element[5] = 205
Element[6] = 206
Element[7] = 207
Types Of Array:-
1)One Dimensional Array
2)Two Dimensional Array
3)Multidimensional Array
This Will Describe In next Posts:-
-:PLEASE SHARE US:-
-:THANKS A LOT:-
Comments
Post a Comment