Repository navigation
Expand file tree
/
Copy pathLecture29.cpp
More file actions
68 lines (52 loc) · 1.46 KB
/
Copy pathLecture29.cpp
File metadata and controls
68 lines (52 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
int main(){
// jagged array :-
int *jaggedarray[3]; // array containing 3 rows
// allocate memory for rows and assign their address to jaggedarray
jaggedarray[0] = new int[2] {1,2};
jaggedarray[1] = new int[3] {1,2,3};
jaggedarray[2] = new int[4] {1,2,3,4};
//taking output
cout << endl;
for(int i=0; i<3; i++) {
for(int j=0; j<i+2; j++) {
cout << jaggedarray[i][j] << " ";
} cout << endl;
//releasing memory
for(int i=0; i<3; i++) {
delete [] jaggedarray[i];
}
// 2-D array :-
int row;
cin >> row;
int col;
cin >> col;
//creating a 2D array
int** arr = new int*[row];
for(int i=0; i<row; i++) {
arr[i] = new int[col];
}
//taking input
for(int i=0; i<row; i++) {
for(int j=0; j<col; j++) {
cin >> arr[i][j];
}
}
//taking output
cout << endl;
for(int i=0; i<row; i++) {
for(int j=0; j<col; j++) {
cout << arr[i][j] << " ";
} cout << endl;
}
//releasing memory
for(int i=0; i<row; i++) {
delete [] arr[i];
}
delete []arr;
//how to create a 2D array dynamically
//input/Output
//memory free kaise karani hai
return 0;
}