LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1057|回复: 3

弱智的问一个c语言的问题!希望高手解答!

[复制链接]
发表于 2006-11-21 17:25:52 | 显示全部楼层 |阅读模式
以下语句:
error: int i = 0;

为什么提示语法错误

只有改成 error: {int i = 0;} 才可以?

这是为什么?
发表于 2006-11-21 18:20:04 | 显示全部楼层
Post by aishen944
以下语句:
error: int i = 0;

为什么提示语法错误

只有改成 error: {int i = 0;} 才可以?

这是为什么?


error是标号吗?

C语言不支持这种定义变量的形式,
加了{}后就是局部变量
回复 支持 反对

使用道具 举报

发表于 2006-11-21 22:51:25 | 显示全部楼层
error:; int i = 0; 就可以了
回复 支持 反对

使用道具 举报

发表于 2006-11-22 13:21:42 | 显示全部楼层
参看 http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1124.pdf
  1. 6.8.1 Labeled statements
  2. Syntax
  3. labeled-statement:
  4.         identifier : statement
  5.         case constant-expression : statement
  6.         default : statement
复制代码
int i = 0; 好像不是 statement...
  1. 6.8 Statements and blocks
  2. Syntax
  3. 1 statement:
  4.         labeled-statement
  5.         compound-statement
  6.         expression-statement
  7.         selection-statement
  8.         iteration-statement
  9.         jump-statement
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表