简体   繁体   English

在这个程序中请解释输出

[英]In this program please explain the output

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?这里我们没有给p分配任何地址,那为什么它甚至打印任何东西? And c is assigned NULL so this means it stores the value as 0 ?并且c被分配了NULL所以这意味着它将值存储为0

Here we haven't assigned any address to p then why is it even printing anything?这里我们没有给 p 分配任何地址,那为什么它甚至打印任何东西?

You called printf() , so it has to print something .你调用了printf() ,所以它必须打印一些东西 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?并且 c 被分配了 NULL 所以这意味着它将值存储为 0?

Yes, NULL is a macro that expands to either 0 , (char *)0 , or something equivalent.是的, NULL是一个扩展为0(char *)0或等价物的宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM