-
After new, it is to apply for a piece of memory to p, and more importantly, to tell the system that this memory space has been requested, and if you apply for it elsewhere in the future, it will not be allocated to this address.
delete, is to tell the system that this address has been abandoned, and if there is still room to apply in the future, this memory can be allocated, but at this time, p and the contents of this memory are not emptied.
That is to say, p is still pointing to this space, which is very dangerous, so after release, p=null must be manually set; Yes.
Otherwise, if another variable applies to the space that the original p points to, then using p to manipulate the memory again will cause a fatal error. Therefore, it is necessary to leave the pointer blank in the future.
-
To use an analogy, memory is like a house.
new is to buy a house.
To delete is to sell the house.
The house is not destroyed, it is still there. You can still put something in it. But this is clearly not legal anymore. In the future, if the things you put in are disposed of by others, you can't complain about it.
-
The memory is freed, but p is still the same address, p[0], p[1] will still read the data in the order of the address, and the content of the memory is unchanged, but it can be used by other variables in the program instead of occupying it.
-
new allocates memory.
The common format is: type name * pointer = new type name;
e.g. int * pi = new int;
Types can be basic data types, structs, custom classes, and so on to free up memory.
The common format is: delete pointer name;
Note that delete is paired with new, and only the memory allocated by new can be released.
Delete can only be used once, not twice.
new to create a dynamic array.
The general format is: type name * pointer = new type name [ array size ];
e.g. char * pc = new char [234];
pc is assigned the address of the first element, pointing to the first element delete to release the dynamic array.
The common format is: delete pointer;
new, the pointer can be used as the array name, e.g. float * pf = new float [200];
pf[24], which is the value of the 25th element of the array, the subscript starts at 0 and new and delete are used in C++ to dynamically allocate memory, and C uses malloc and free
-
Yes, Malloc and Free are standard library functions in C++ C, and New Delete is an operator in C++.
Functionally, they are all used to apply for and free up memory.
That page of the space may have been added malicious**, please check carefully! >>>More
The landlord is confusing the practical with the abstract. Points, lines, and planes are all abstracted by people, and these things do not exist in real life, they are all bodies. In philosophy, a point is the smallest unit that cannot be divided, in mathematics a point is something represented by a string of coordinate values, and in physics a point is a mass "concept". >>>More
This involves basic limit thinking. The answer is just as much. >>>More
Open the space. Click Customize Module. Press New Module - select ** Module - and then enter the desired word in the box.
For a long time, dimensions have been very profound for us, and the dimensions that people can understand are only in one, two, and three, and the four-dimensional space is complex enough, and the dimensions above are more difficult, and scientists are trying to explain this. In many science fiction works, the existence of dimensions restricts the development of civilizations, and many advanced civilizations exist in high dimensions, and human beings must break through dimensions if they want to develop, which has been recognized by many people. In the opinion of scientists, in order to break through the dimensional limits, we also need to find a substance. >>>More