What is the initial value of a point in c ?
Texture* texture;
what is the value of this pointer, is it nullptr is it NULL? I heard somwhere that the operating system might choose this is that true and is it safe to declare a pointer like this?
CodePudding user response:
The C language does not specify any initial value for a pointer, leaving it uninitialized could lead to undefined behavior. Some compilers will have a debug mode where a pointer will be initialized to a value that is likely to lead to a crash.
CodePudding user response:
Depends on where it is allocated. If static then 0. Ie like this
#include <stdio.h>
....
Texture* texture; // all statics are initialized to 0
On the stack, like this
int pooble(){
Texture* texture;
...
}
then its value is undefined. Using it results in Undefeined Behaviour
function local statics are also initialized to 0
int pooble(){
static Texture* texture; // =0
...
}