2016-03-03 129 views
-2

我不断收到这个错误,“错误:使用未声明的标识符”,Ive搜遍了,他们告诉我说我还没有声明'nbr'。我有。这一点的关键是要制作一个指向整数值的指针,并且您必须能够使用指针设置整数的值,我真的迷失在这里......如果有人能够深入解释会很棒的。看到下面的代码...谢谢...在C:编译时出错

#include <unistd.h> 

void ft_ft(int *nbr) 
{ 
int a; 
*nbr = a; 
} 
int main() 
{ 
ft_ft(*nbr); 
return 0; 
} 

备注:我不能使用stdio.h,我不能使用其他.c或.h文件。我不能添加任何其他功能。

+0

如果你已经声明了它,那么你没有显示它。如果这是您的实际代码,请解释您在哪里申报的代码 – Default

+0

请缩进您的代码。 –

+0

请缩进您的代码并阅读C范围规则。 –

回答

5
int main() 
{ 
    ft_ft(*nbr); 
    return 0; 
} 

这是开始执行,和NBR尚未定义,除了ft_ft()的范围内,作为一个参数,以进行传递。变量需要定义和值是有意义的前将它传递给一个函数。

1
#include <unistd.h>  // declare a whole bunch of identifiers you never use 

void ft_ft(int *nbr) // declare the identifiers ft_ft, and nbr 
          // ft_ft scope is the whole file from this point onwards 
          // nbr's scope is the ft_ft function 
{ 
int a;     // declare the identifier a 
          // a's scope is from here to the end of the function at the next } 
*nbr = a;     // use nbr and a 
} 
int main()    // declare the identifier main with scope to the end of the file 
{ 
ft_ft(*nbr);    // use the declared identifier ft_ft 
          // with an undeclared nbr 
return 0; 
}