what is this ‘new’ operator used and what is the basic meaning of char *output=new char[let say 5]
About the new operator
The primary purpose of new operator is to allocate memory for a variable or an object during run time. When new operator is used, the variables/objects are considered to be pointers to the memory location allocated to them.
Also,
char a[5];
char b* = new char[5];
The difference in the two is that
char a[5] allocates 5 chars on the stack memory.
new char[5] allocates 5 chars on the heap memory.
The heap has its manager and can allocate variable amounts of memory.
1 Like
thanks a lot for the help