C语言的条件编译为什么不能正常运行

来源:百度知道 编辑:UC知道 时间:2024/07/02 05:39:44
请教书中例题在VC6.0中为什么不能运行?
# include <stdio.h>
main()
{
# if NULL
printf("NULL为非零值!\n");
# else
printf("NULL为零值!\n");
}
谢谢高手给予指点!

# include <stdio.h>
main()
{
#if _NULL //#号与if之间不要空格,再者,NULL前要加一下划线.
printf("NULL为非零值!\n");
#else
printf("NULL为零值!\n");
#endif //不要忘了在IF判断后加上结束符endif

}

编译已通过!!
你可以去试试了.
课本上的东西不一定都是对的.要相信自己的判断

//#include<iostream>
//using namespace std;
# include <stdio.h>
void main()
{
if (NULL)
printf("NULL为非零值!\n");
else
printf("NULL为零值!\n");
}
少个括号,去掉#号

#号去掉