Array Declaration in Programming Languages
Array Declaration in Programming Languages
Group 5
Presented by:
Muhammad Salman
Muhammad Afnan
Bachelor's Semester (RS and GIS).
Submitted to:
Ms. Kinza Noor
Understandin
g
Array, its
Types
&
Initialization
Definition:
Identifier”
Types of Arrray:
Without Array:
int num1=10; int num2=20 ;
int num3=30 ; int num4=40 ;
Using Array:
int num[4]= {10,20,30,40} ;
Index of Array
Zero-Based Indexing: In C, array indices start from 0. This means that
the first element of an array is at index 0, the second element is at
index 1, and so on.
Unique Identifier: Each element in an array has a unique index that
distinguishes
Index 0 Index1 Index2
Index3
it from other
10 elements.
20 30 40
To call data by index:
printf(%d, num[0]); printf(%d, num[1]);
“Array declaration is the process of defining the “Array initialization is the process of
characteristics of an array” assigning values to the elements of
an array.”
Data type: The type of data that the array will hold
Name: The identifier or name given to the array. Example:
Size: The number of elements that the array will
int scores[4] = {10, 20, 30, 40, };
hold.
OR
int scores[4];
data_type array_name[array_size]; scores[0] = 10;
scores[1] = 20;
e.g: int num[4] scores[2] = 30;
scores[3] = 40;
Types of Array
1) One Dimensional Array:
“It is a data structure that stores a collection
of elements of the same data type in a single
row or column.”
Key Characteristics: int scores[5] = {90, 80, 70, 60, 50};
Single Row or Column: A 1D array stores elements in a single row or column, unlike multi-dimensional
arrays that store elements in rows and columns.
Same Data Type: All elements in a 1D array must be of the same data type, such as integers, floating-
point numbers, or characters.
Indexed Elements: Each element in a 1D array is identified by an index or subscript, whichallows for
efficient access and manipulation.
Practical: Output Explanation:
num[0] = 10
#include <stdio.h> num[1] = 20 [4]: This specifies the size of the array, which is 4 elements.
num[2] = 30
int main() { num[3] = 40 (int i = 0; i < 4; i++): This is the loop control statement.
int i = 0: Initializes a variable i to 0.
int num[4] = {10, 20, 30, 40}; i < 4: Specifies the condition for the loop to continue. As
for (int i = 0; i < 4; i++) { ` long as i is less than 4, the loop will execute.
i++: Increments the value of i by 1 after each iteration.
printf("num[%d] = %d\n", i, num[i]);
0 10 20 30
1 40 50 60
Key Characteristics:
(int num[2][3] = {10, 20, 30,40, 50, 60})
It store elements in table-like structure with rows and columns.
In 2-d array variable are declared using two pair of square brackets. i.e: [2]
[3].
int num[2][3] = {
{{13,14,15,16}, 2 9 10 11 12
{17, 18,19,20}, 0 1 2 3
{21,22,23,24,}}
}; 0 13 14 15 16
1 40 50 60