+ 4
How use new and delete operators in c++?
2 Réponses
+ 3
new and delete operators are used with the pointers
When you create a pointer :
- the pointer can point to an existing variable : *p = &var
- or it can point to a new variable : *p = new int;
In the second example, we create an int variable and we point to it.
When you create variables using new, you must erase it from the memory by using delete when you don't need it anymore.
+ 1
new and delete operators are used with the pointers
When you create a pointer :
- the pointer can point to an existing variable : *p = &var
- or it can point to a new variable : *p = new int;
In the second example, we create an int variable and we point to it.
When you create variables using new, you must erase it from the memory by using delete when you don't need it anymore.