定义函数的时候(int,int,int)和(int x,int y,int z)有什么区别? 什么时

定义函数的时候(int,int,int)和(int x,int y,int z)有什么区别? 什么时候可以省略参数

函数的声明,要在 主函数之前。 比如: 写求字符串函数 (1) 你可以在 主函数前写,会正确。比如: int stringLength(char *p) { int count = 0; while ( *p != 0) count++; return count; } int main() { printf("%d",stringLength("Hello World !")); } (2) 你可以在 主函数 之后 写,会报错确。(也 编译器不报错,但是原则上是错误的)比如: int main() { printf("%d",stringLength("Hello World !")); } int stringLength(char *p) { int count = 0; while ( *p != 0) count++; return count; } (3) 这个时候, 1.你就 必须在 主函数之前写。 2.在主函数前,申明这个函数 int strLength(char *) ; 这个时候,就可以 不用 形参。 整个例子。 int strLength(char *) ; int main() { printf("%d",stringLength("Hello World !")); } int stringLength(char *p) { int count = 0; while ( *p != 0) count++; return count; }
温馨提示:答案为网友推荐,仅供参考