Am I so confused that I dedicate myself to sweeping instead of programming?
hehe
If you do
void unafuncion( ) {
int a = 10;
...
}
At some point would you release 10
? No, because it is a literal . No It makes sense to release it, it is impossible. It is embedded in the source code of our program.
Or would you release a
? Well either, because it is a local variable to the function; solita is already released.
Well with nullptr
it's the same. In itself it is a literal (== 0). It does not make sense to free it.
All this comes from a theme, the pointers, which is durillo , but, if you think about it carefully, you'll see that it's simpler than it seems.
struct Algo {
char name[20];
int temperatura;
};
What is temperatura
? From the point of view of the compiler, it is not more than a memory area, of a certain size, and that admits certain operations.
We are the ones who add meaning semantic . I know that temperatura
stores just that, referring to the city whose name I have stored in name
. And, if I want my program to work, I have to be careful with what I store there, so that values are consistent to what I have decided to do with them .
Well, the same thing happens with the pointers. For the compiler, a pointer is a data type like any other; It occupies a certain size, and certain operators can apply it. One of those operations is to use it as indirect access to a memory address, to read or write it.
The semantic value of a pointer is our thing. The decision to assign the value 0
; or use it to store the result of a search; or place the address of a memory block returned by new
.
All those things are interpretations that WE make the value of the pointer; the compiler does not know anything about it, and simply tells us if we try to do odd or incorrect things. For the compiler, the pointer remains a simple data, like any other.
By this I mean that if you do int *alto = nullptr;
, the compiler does not assume or know anything. Does not allocate memory; he just checks that the types are comparative, and to throw p'alante .