I was purposely trying to get a NULL pointer in C but I failed to do this. Here is what I was coding:
int main(void) {
int x; //UNINITIALIZED so that it will represent "nothing"
int *null_test = &x;
printf("This should be null %p \n", null_test);
}
But it gave me an address: 0x7fd96c300020 which doesnt seem to be NULL as I was hoping.
Why? I didn't even initializex but still not null?
NULLtonull_test.int *null_test = 0;int xdefines anint. Anintcannot beNULLby definition. Just a pointer can beNULL.null_test. Is taking the address without reading from it undefined behaviour?