在C中,当我在函数体之前声明函数签名后面的变量时,它意味着什么?

时间:2012-10-07 01:26:25

标签: c function syntax compiler-errors method-signature

  

可能重复:
  Why are declarations put between func() and {}?

在C中,当我在函数体之前声明一个函数签名后面的变量时它是什么意思?

示例:

int foo (i) int i {
    printf ("the value of variable 'i' is: %d", i);
    return i;
}

当我编译代码以及初始化变量i时,我得到一个编译错误: “无法初始化参数:p”

1 个答案:

答案 0 :(得分:5)

这意味着您正在查看旧代码。 这是旧的K& R语法 基本上它说, i 是参数,它是 int

您可以将其重写为

int foo (int i) 
{
    printf ("the value of variable 'i' is: %d", i);
    return i;
}