0% found this document useful (0 votes)
13 views15 pages

Array Declaration in Programming Languages

The document provides an overview of arrays, their types, and initialization in programming. It explains one-dimensional, two-dimensional, three-dimensional, and multi-dimensional arrays, along with their characteristics and examples of declaration and usage. Key concepts such as zero-based indexing and the differences between array declaration and initialization are also discussed.

Uploaded by

mzainsafdarjutt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
13 views15 pages

Array Declaration in Programming Languages

The document provides an overview of arrays, their types, and initialization in programming. It explains one-dimensional, two-dimensional, three-dimensional, and multi-dimensional arrays, along with their characteristics and examples of declaration and usage. Key concepts such as zero-based indexing and the differences between array declaration and initialization are also discussed.

Uploaded by

mzainsafdarjutt
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 15

g

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:

“Array is a way to take Multiple values


(of same categories) using singleA.

Identifier”
Types of Arrray:

1. One dimensional Array 2. Two dimensional Array

3.Three dimensional Array 4. Multi- dimentional Array


Basic structure: e.g: Int num[3]={12,13,14};
Data type = int
Array name = num
Data-type, Array name , [content size] Content size = [3]

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]);

printf(%d, num[2]); printf(%d, num[3]);


Array Declaration: Array Initialization:

“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]);

} Loop control statements: In C programming language


are essential tools that allow for the execution of certain
return 0;
} operations repeatedly until a specified condition is met.
Two Dimensional Array:

“It is a data structure that stores a collection of elements


of the same data type in a table-like structure with rows
and columns”
0 1 2

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].

 It is more complex than 1-D due to rows and columns.


Practical Program execution in
Output
10 20 30 software
#include <stdio.h> 40 50 60
int main() {

int num[2][3] = {

{10, 20, 30},


{40, 50, 60}
};

for (int i = 0; i < 2; i++) {

for (int j = 0; j < 3; j++) {

printf("%d ", num[i][j]);


}
printf("\n");
}
return 0; }
Three Dimensional Array:

“It is a data structure that stores a collection of elements of the


same data type in a three-dimensional space.” A.

int num[2][3][4]= { {{1, 2,3, 4}, 0 1 2 3


{5, 6, 7, 8}, 0 1 2 3 4
{9,10,11,132}},
1 5 6 7 8

{{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

 A three-dimensional array, also known 1 17 18 19 20


as a 3D array or a cubic array. 2 21 22 23 24
Practical Program execution in
#include <stdio.h>
int main() { Outout software
int num[2][3][4] = { 1234
{{1, 2, 3, 4}, 5678
{5, 6, 7, 8}, 9 10 11 12
{9, 10, 11, 12}},
13 14 15 16
17 18 19 20
{{13, 14, 15, 16}, 21 22 23 24
{17, 18, 19, 20},
{21, 22, 23, 24}} };
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 4; k++) {
printf("%d ", num[i][j][k]);
}
printf("\n");
}
printf("\n");
} return 0;}
Multi-Dimensional Array:

“A multi-dimensional array is an array with more than


one level or dimension. Such as a 2D array, or two-
dimensional array and 3-D or cubic array”

Example of 2-D Array:


0 1 2
0 10 20 30

1 40 50 60

(int num[2][3] = {10, 20, 30,40, 50, 60})

You might also like