C 错误:";隐式函数声明……”;关于我的所有职能
这是密码C 错误:";隐式函数声明……”;关于我的所有职能,c,C,这是密码 main() { short sMax = SHRT_MAX; int iMax = INT_MAX; long lMax = LONG_MAX; // Printing min and max values for types short, int and long using constants printf("range of short int: %i ... %i\n", SHRT_MIN, SHRT_MAX); printf
main()
{
short sMax = SHRT_MAX;
int iMax = INT_MAX;
long lMax = LONG_MAX;
// Printing min and max values for types short, int and long using constants
printf("range of short int: %i ... %i\n", SHRT_MIN, SHRT_MAX);
printf("range of int: %d ... %d\n", INT_MIN, INT_MAX);
printf("range of long int: %ld ... %ld\n", LONG_MIN, LONG_MAX);
// Computing and printing the same values using knowledge of binary numbers
// Short
int computed_sMax = computeShort() / 2;
printf("\n Computed max and min short values: \n %i ... ", computed_sMax);
int computed_sMin = (computeShort()/2 + 1) * -1;
printf("%i\n", computed_sMin);
//Int
int computed_iMax = computeInt() / 2;
printf("\n Computed min and max int values: \n %i ... ", computed_iMax);
int computed_iMin = computeInt() / 2;
printf("%i", computed_iMin);
return 0;
}
int computeShort()
{
int myShort = 0;
int min = 0;
int max = 16;
for (int i = min; i < max; i++)
{
myShort = myShort + pow(2, i);
}
return myShort;
}
int computeInt()
{
int myInt = 0;
int min = 0;
int max = 32;
for (int i = min; i < max; i++)
{
myInt = myInt + pow(2, i);
}
return myInt;
}
main()
{
短sMax=SHRT_MAX;
int iMax=int_MAX;
long lMax=long_MAX;
//使用常量打印short、int和long类型的最小值和最大值
printf(“短整数的范围:%i…%i\n”,最小值,最大值);
printf(“整数范围:%d…%d\n”,整数最小值,整数最大值);
printf(“长整数范围:%ld…%ld\n”,长最小值,长最大值);
//使用二进制数知识计算和打印相同的值
//短
int computed_sMax=computeShort()/2;
printf(“\n计算的最大和最小短值:\n%i…”,计算的\u sMax);
int computed_sMin=(computeShort()/2+1)*-1;
printf(“%i\n”,computed\u sMin);
//Int
int computed_iMax=computeInt()/2;
printf(“\n计算的最小和最大int值:\n%i…”,计算的\u iMax);
int computed_iMin=computeInt()/2;
printf(“%i”,计算得出);
返回0;
}
int computeShort()
{
int myShort=0;
int min=0;
int max=16;
对于(int i=min;i
调用函数之前必须声明函数。即使对于标准库的某些部分也是如此
例如,printf()
#include <stdio.h>
#包括
对于您自己的功能,请选择:
- 将定义移到上面的
main()
;这些定义也可以作为声明
- 在调用之前添加原型,通常在
main()
之前:
int computeShort()代码>
另外,请注意
- 本地函数应该声明为静态的
- 不接受任何参数的函数的参数列表应为
(void)
,而不是()
,这意味着其他内容
在使用函数之前,必须声明函数:
int computeShort(); // declaration here
int main()
{
computeShort();
}
int computeShort()
{
// definition here
}
另一种方法是在main之前定义函数,但不太可取,因为该定义也用作声明:
int computeShort()
{
// return 4;
}
int main()
{
computeShort();
}
但是一般来说,更好的做法是为所使用的函数单独声明,因为这样您就不必在实现中维护特定的顺序