edited by
617 views
0 votes
0 votes

is it dangling pointer ?

int main(void) {
      int* p;
printf("%d",*p);
    return 0;
}
 

https://ideone.com/IN77el

edited by

1 Answer

0 votes
0 votes

Wild Pointer

A pointer which is not initialized with any address( not even NULL) is called a wild pointer. The wild pointer is by default stored with the garbage value.

Be clear that there is difference among the NULL pointer and wild pointer. The NULL pointer is assigned with the address 0 where as wild pointer is not assigned with any address.

#include <stdio.h>

int main(void) { 
      int* p; 
printf("%d",*p); 
    // your code goes here 
    return 0; 

=> Here p is the pointer pointing nothing, stored with the garbage value

Important Points

  1. NULL vs Uninitialized pointer – An uninitialized pointer stores an undefined value. A null pointer stores a defined value, but one that is defined by the environment to not be a valid address for any member or object.
  2. NULL vs Void Pointer – Null pointer is a value, while void pointer is a type

Related questions

0 votes
0 votes
1 answer
2
iarnav asked May 5, 2017
670 views
#include <stdio.h int*fun() { intx=5; return&x; } int main(){ int*p=fun(); fflush(stdin); printf("%d",*p); return0; }Please explain this code, how's it's working line by ...