Usually, variables are deleted when out of scope.
Code:
int *pointer;
{
int number = 5;
pointer = &number;
}
// now, outside the brackets, pointer points to freed memory and should not be used.
Am I right so far?
Text have the type (const char*), so I figured that text are arrays of chars stored in memory, and that (const char*) points to the first element.
That's all good.
But take a look at this code:
Code:
const char *pointer;
{
const char *text = "This is a text";
pointer = text;
}
// What about pointer(outside of brackets) here?
Isnt text freed when out of scope in C?
If so, is this because text-constants are created using malloc, behind the scences?
And if so, If i were to create a program with LOTS of text, wouldnt I need to manually free memory taken from text-constants?