Presentedby:
Mk dheeran
Teach guru
Introduction to
Arrays
What is an array ?
✘ Array is a collection of similar data items are
stored under a common name.
✘ It is a continuous memory location.
✘ The lowest address corresponds to the first
element and largest address to the last element.
✘ Example:
a[3]={1,2,3}
3
Classification of arrays:
 Depending upon the number of subscripts used,
arrays are classified into three types
1. One-dimensional array
2. Two- dimensional array
3. Multi – dimensional array
4
One Dimensional Array:
Syntax:
data_typevariable_name[dimensional/size of an array];
Example:
a[5]={1,2,3,4,5}
5
Name a[0] a[1] a[2] a[3] a[4]
Value 1 2 3 4 5
Address 1000 1001 1002 1003 1004
Initialization:
An array can be initialized at
I. compile time
II. run time
✘ After declaration ,the array elements must be
initialized otherwise they hold garbage value.
6
1.Compile time initialization:
 Initialization at the time of the declaration is known as compile time
initialization.
Syntax:
data_typevariable_name[dimensional/size of an array]={value1, value2,…value n};
Example:
• int a[5]={1,2,3,4,5};
• int b[]={1,2,3,4,5};
• char name[]={‘A’,’B’,’C’};
7
2. Run time initialization:
 When the array have large number of elements then the
array elements can be initialize at run time.
Syntax:
scanf(“format specifier”, &variablename[size] );
8
9
Thank you..

Array in c programming

  • 1.
  • 2.
  • 3.
    What is anarray ? ✘ Array is a collection of similar data items are stored under a common name. ✘ It is a continuous memory location. ✘ The lowest address corresponds to the first element and largest address to the last element. ✘ Example: a[3]={1,2,3} 3
  • 4.
    Classification of arrays: Depending upon the number of subscripts used, arrays are classified into three types 1. One-dimensional array 2. Two- dimensional array 3. Multi – dimensional array 4
  • 5.
    One Dimensional Array: Syntax: data_typevariable_name[dimensional/sizeof an array]; Example: a[5]={1,2,3,4,5} 5 Name a[0] a[1] a[2] a[3] a[4] Value 1 2 3 4 5 Address 1000 1001 1002 1003 1004
  • 6.
    Initialization: An array canbe initialized at I. compile time II. run time ✘ After declaration ,the array elements must be initialized otherwise they hold garbage value. 6
  • 7.
    1.Compile time initialization: Initialization at the time of the declaration is known as compile time initialization. Syntax: data_typevariable_name[dimensional/size of an array]={value1, value2,…value n}; Example: • int a[5]={1,2,3,4,5}; • int b[]={1,2,3,4,5}; • char name[]={‘A’,’B’,’C’}; 7
  • 8.
    2. Run timeinitialization:  When the array have large number of elements then the array elements can be initialize at run time. Syntax: scanf(“format specifier”, &variablename[size] ); 8
  • 9.