Isn't a pointer gloabal?

It should be right? It points to an adress so scope shouldn't matter.
It's more the case that the memory pointed to is globally accessible. A given pointer variable can be global or local like any other variable.

So if you allocate memory using a local variable, and it goes out of scope before the address is either passed to another variable or the memory deleted, then you have no way of getting at or freeing the block of memory that you allocated (ie a memory leak)

So scope can and does matter!


Last edited on
Yes, to be clear, scope always matters.
Topic archived. No new replies allowed.