From 086ea137c718643302705ced03ca074bb7b83c4c Mon Sep 17 00:00:00 2001 From: Erik Alexander Sandvik Date: Sat, 31 Aug 2019 16:15:53 +0200 Subject: [PATCH] Added program on dynamical alloc. of memory and input from c-line --- dynamicalallocationofmemory.cpp | 15 +++++++++++++++ inputfromcommandline.cpp | 11 +++++++++++ test.cpp | 14 ++++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 dynamicalallocationofmemory.cpp create mode 100644 inputfromcommandline.cpp diff --git a/dynamicalallocationofmemory.cpp b/dynamicalallocationofmemory.cpp new file mode 100644 index 0000000..c4d6b7c --- /dev/null +++ b/dynamicalallocationofmemory.cpp @@ -0,0 +1,15 @@ +#include + +using namespace std; + +int main() +{ + int n; + cin >> n; + + + double* b = new double[n]; // Using this approach, we do not + // have to declare n as constant + + return 0; +} diff --git a/inputfromcommandline.cpp b/inputfromcommandline.cpp new file mode 100644 index 0000000..210f2eb --- /dev/null +++ b/inputfromcommandline.cpp @@ -0,0 +1,11 @@ +#include + +using namespace std; + +int main(int argc, char* argv[]) // Add this rubbish to main +{ + // argv[0] is the program name + // arg[1] is the first argument + // arg[2] is the second argument and so on + return 0; +} diff --git a/test.cpp b/test.cpp index 0c053b8..e60dc11 100644 --- a/test.cpp +++ b/test.cpp @@ -9,11 +9,17 @@ using namespace std; +int func(int, int); + int main() { - const int n = 5; - double b[n] = {}; - n = 2; - } + int a = 1, b = 2; + cout << func(a, b); + return 0; +} + +int func(int a, int b) +{ + return a + b; }