+ 1
Please explain about the 'new'.
Why do we need it and how it is most often used in programming?
4 Antworten
+ 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;
}
+ 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
0
Thanks, but can u send me code's, in which uses 'new'?
0
Thanks, will understand.