c++ new int usage

The new operation creates an object and creates a memory space for the object, and finally returns a pointer to the memory.

  1. int *a = new int(10); //Create an integer dynamically , no parameter is * a=0, if there is a parameter, * a = parameter
  2. int *p = new int[10]; //Create a dynamic integer array with 10 elements , without assignment, and the elements are random numbers
  3. int *p = new int[10] (); //Create a dynamic integer array with 10 elements , and assign the value 0

Guess you like

Origin blog.csdn.net/h799710/article/details/107794434