0
What is new int ?
int *x; x=new int[5];
5 Answers
+ 3
Here you define an array that has space to store 5 integers.
'new' is a keyword that creates an object and allocates memory for it.
+ 6
variableType variableName=
new VariableType[arraySize]
string *x=new string[8]
char *v=new char[66];
as Steppenwolf said..
an array of ints
+ 3
int *x is a pointer to a spot in memory that will hold an integer.
When you use 'new int[5]' you are telling the system to allocate memory for five integers, and by assigning it to x, you are giving the address of those five integers to the pointer. Just remember to deallocate that memory when you're done using it with:
delete [ ] x;
+ 1
Gaurav Sahadev , new is the keyword to allocate memory dynamically...
Memory is divided into stack and heap.. In stack, it is static memory and if you do int a or int a[5], static memory is allocated which in turn automatically gets free by end of your code scope...
once you do new int[5], memory from heap is allocated, which you should free using delete operator... On stack, for your case, only pointer pointing to your array of 5 int is allocated... that pointer is free automatically at end of scope...
+ 1