0

Dynamic allocation in c++

I'm beginner to programming language and I'm not understanding the concept of dynamic allocation. why do we use it? my professor said that it can assign memory space at run time but we can also use cin for this purpose . for example: int a; cin>>a; int arr [a]; so what's the point here to use it? Thanks in advance.

14th May 2018, 5:12 PM
Maleeha Khalid
Maleeha Khalid  - avatar
1 ответ
+ 7
Dynamic memory allocation in C/C++ refers to performing memory allocation manually by programmer. Dynamically allocated memory is allocated on Heap and non-static and local variables get memory allocated on Stack https://www.geeksforgeeks.org/new-and-delete-operators-in-cpp-for-dynamic-memory/ Standard input (cin) In most program environments, the standard input by default is the keyboard, and the C++ stream object defined to access it is cin. For formatted input operations, cin is used together with the extraction operator, which is written as >> (i.e., two "greater than" signs). This operator is then followed by the variable where the extracted data is stored. For example: int age; cin >> age;
14th May 2018, 5:31 PM
Scooby
Scooby - avatar