Please explain about the 'new'. | Sololearn: Learn to code for FREE!
Nowy kurs! Każdy programista powinien nauczyć się Generative AI!
Wypróbuj darmową lekcję
+ 1

Please explain about the 'new'.

Why do we need it and how it is most often used in programming?

30th Jul 2016, 8:01 AM
Alexander T.
Alexander T. - avatar
4 odpowiedzi
+ 3
#include <iostream> using namespace std; int main() { int *a = new int; // Announce pointer for variable type int int *b = new int(5); // initialization of pointer *a = 10; *b = *a + *b; cout << "b is " << *b << endl; // recleaning of the memory delete b; delete a; return 0; }
30th Jul 2016, 9:49 AM
Antoshafor
Antoshafor - avatar
+ 1
New is a keyword which is used to declare dynamic memory. It's size can be modified as required by the program during the runtime. It is often used to create data structures like stack, queue, trees etc
30th Jul 2016, 8:07 AM
Debabrata Behera
Debabrata Behera - avatar
0
Thanks, but can u send me code's, in which uses 'new'?
30th Jul 2016, 9:10 AM
Alexander T.
Alexander T. - avatar
0
Thanks, will understand.
30th Jul 2016, 10:00 AM
Alexander T.
Alexander T. - avatar