-3
void main()
{
    int a=5,*p,*c=NULL;
    printf("p=%u",p);    //OUTPUT p=3839036080
    printf("\nc=%u",c);  //OUTPUT c=0

}

Here we haven't assigned any address to p then why is it even printing anything? And c is assigned NULL so this means it stores the value as 0?

Barmar
  • 741,623
  • 53
  • 500
  • 612
guptasaanika
  • 137
  • 1
  • 3
  • 9
  • Don't uninitialised variables have some value even though those are garbage values. Pointer is also a variable: a named location in memory. – Aditi Rawat Oct 31 '17 at 19:24
  • [Is NULL always zero in C?](https://stackoverflow.com/q/9894013/669576) – 001 Oct 31 '17 at 19:25
  • *Here we haven't assigned any address to p then why is it even printing anything* - what would you expect it to do? – Eugene Sh. Oct 31 '17 at 19:25
  • [What happens to a declared, uninitialized variable in C? Does it have a value?](https://stackoverflow.com/q/1597405/669576) – 001 Oct 31 '17 at 19:26
  • memory has one of two states .. 0 or 1. There is no third "nothing" value. If you have some memory that you haven't assigned anything to (`p`) then _something_ is still there. – yano Oct 31 '17 at 19:26
  • You should learn to search for this stuff on your own. – 001 Oct 31 '17 at 19:27

1 Answers1

0

Here we haven't assigned any address to p then why is it even printing anything?

You called printf(), so it has to print something. The variable is uninitialized, so it prints whatever happened to be in the memory used to hold the variable.

And c is assigned NULL so this means it stores the value as 0?

Yes, NULL is a macro that expands to either 0, (char *)0, or something equivalent.

Barmar
  • 741,623
  • 53
  • 500
  • 612