语法tips 1

来源:互联网 发布:帝国cms搜索页面模板 编辑:程序博客网 时间:2024/06/15 03:25

#include <stdio.h>

int main(void)

{

if(0);

{

printf("zhou\r\n");

}

return;

}


源于一个失误,if后面误跟了一个;会发生什么?

居然编译通过了,居然也执行了,运行结果“zhou”。if(0)合理的被;结束。


再试:

#include <stdio.h>

int main(void)

{

{

printf("zhou  ");

}

{

printf("again\r\n");

}

return;

}


编译通过了,运行结果“zhou  again”。


这么看来以前认为必须要跟随在if、while等后面的{},独立起来也能用,这特性别的用处似乎没有,但在编辑软件中能起到折叠显示的作用哦,还是不错的。


add。。。

{}居然是个作用域:

int fun(void)

{

int zhou;

{

struct tm * ptr;

//ptr只能在这里面用

//zhou里外都一样

}

ptr不能再括号外面用

//zhou里外都一样


return 0;

}


0 0
原创粉丝点击