1.

What is new operator in C++? Give an example.

Answer»

The new operator in C++ is used for dynamic storage allocation. This operator can be used to create an object of any type.

General syntax of the new operator in C++:

The general syntax of a new operator in C++ is as follows:
pointer variable = new datatype;
In the above statement, new is a keyword and the pointer variable is a variable of type datatype.

For example:

int *a=new int;
In the above example, the new operator allocates sufficient memory to hold the object of datatype int and returns a pointer to its starting point. The pointer variable holds the address of memory space allocated.



Discussion

No Comment Found