array declare,initializing,1D array, 2D array

Опубликовано: 19 Июнь 2026
на канале: Rezoana Ahmed Samira
24
0

Declaring Arrays
Array variables are declared identically to variables of their data type, except that the variable name is followed by one pair of square [ ] brackets for each dimension of the array.
one dimensional array:
one dimensional array is like a type of linear array. aacessing it's elements involves a single subscript which can either represent a row or column index.
data type_ array name_[size];
int array[5] = {1,2,3,4,5}// initializing

Initializing Arrays
Arrays may be initialized when they are declared, just as any other variables.
Place the initialization data in curly {} braces following the equals sign. 
The syntax to declare the 2D array is given below

data_type array_name [rows][columns];  
Consider the following example.
int twodimen [4][3]; 
Here, 4 is the number of rows, and 3 is the number of columns.

We will have to define at least the second dimension of the array. The two-dimensional array can be declared and initialize in the following way.
int arr [4][3]={{1,2,3},{2,3,4},{3,4,5},{4,5,6}};