Skip to content

Commit 086ea13

Browse files
committed
Added program on dynamical alloc. of memory and input from c-line
1 parent c4cbf15 commit 086ea13

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

dynamicalallocationofmemory.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
int n;
8+
cin >> n;
9+
10+
11+
double* b = new double[n]; // Using this approach, we do not
12+
// have to declare n as constant
13+
14+
return 0;
15+
}

inputfromcommandline.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
int main(int argc, char* argv[]) // Add this rubbish to main
6+
{
7+
// argv[0] is the program name
8+
// arg[1] is the first argument
9+
// arg[2] is the second argument and so on
10+
return 0;
11+
}

test.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
using namespace std;
1010

1111

12+
int func(int, int);
13+
1214
int main()
1315
{
14-
const int n = 5;
15-
double b[n] = {};
1616

17-
n = 2;
18-
}
17+
int a = 1, b = 2;
18+
cout << func(a, b);
19+
return 0;
20+
}
21+
22+
int func(int a, int b)
23+
{
24+
return a + b;
1925
}

0 commit comments

Comments
 (0)