0% found this document useful (0 votes)
3 views

Array

In C++, an array is a data structure for storing multiple values of the same type in contiguous memory, with syntax defined as data_type array_name[size_of_array]. There are three types of arrays: one-dimensional, two-dimensional, and three-dimensional, each identified by their respective indices. Arrays can also be passed to functions either as individual elements or as whole arrays.

Uploaded by

y08verma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Array

In C++, an array is a data structure for storing multiple values of the same type in contiguous memory, with syntax defined as data_type array_name[size_of_array]. There are three types of arrays: one-dimensional, two-dimensional, and three-dimensional, each identified by their respective indices. Arrays can also be passed to functions either as individual elements or as whole arrays.

Uploaded by

y08verma
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

C++

ARRAY
C++ ARRAY
In C++, an array is a data
structure that is used to store
multiple values of similar data
types in a contiguous memory
location.
SYNTAX: data_type array_name[size_of_array];
EXAMPLE: int arr[5];
Access Array
Elements
You can access elements of an array by indices.
Suppose you declared an array mark as above. The first element
is mark[0], the second element is mark[1] and so on.
Types of Arrays in C++
There are 3 types of an array in C++ :
• One-dimensional array
• Two-dimensional array
• Three-dimensional array

One-Dimensional Array: It stores elements in a single-


dimension.
Two-Dimensional Array:
In this type of array, two indexes describe
each element, the first index represents a
row, and the second index represents a
column.

Syntax of a 2D Array: data_type array_name[m][n];

• m: row number
• n : column number
Three-Dimensional Array:

The 3D array uses three dimensions. There are three indices—the row index, column
index, and depth index to uniquely identify each element in a 3D array.

Syntax of a 3D Array: data_Type


array_name[d][r][c];
• d: space size.
• r : row size.
• c : column size.
Multi-Dimensional Array:
The simplest example of a multidimensional array is a 2-d array; a two-dimensional
array also falls under the category of a multidimensional array. This array can have
any number of dimensions.

Syntax : Datatype array_name [size 1][size 2] . . . . . [size n]

EXAMPLE: int array[5][10][4];


Passing arrays to functions
By passing a particular element of the array to the function

Syntax:
void pass(int arr[10])
{
body
}

Output: The element is 4.


By passing a whole array to the function

Syntax:
void pass(int
arr[])
{
body
}

Output:
The element is 1.
The element is 3.
The element is 9.
The element is 4.
The element is 5.
THANK YOU

You might also like