C primer plus:
Consider the interface description for main(), beginning with the int part.A C++
function called by another function can return a value to the activating (calling) function.That value is called a return value. In this case, main() can return an integer value, as indicated
by the keyword int. Next, note the empty parentheses. In general, a C++ function
can pass information to another function when it calls that function.The portion of the
function header enclosed in parentheses describes that information. In this case, the empty
parentheses mean that the main() function takes no information, or in the usual terminology,
main() takes no arguments. (To say that main() takes no arguments doesn’t mean
that main() is an unreasonable, authoritarian function. Instead, argument is the term computer
buffs use to refer to information passed from one function to another.)
In short, the following function header states that the main() function returns an integer
value to the function that calls it and that main() takes no information from the function
can pass information to another function when it calls that function.The portion of the
function header enclosed in parentheses describes that information. In this case, the empty
parentheses mean that the main() function takes no information, or in the usual terminology,
main() takes no arguments. (To say that main() takes no arguments doesn’t mean
that main() is an unreasonable, authoritarian function. Instead, argument is the term computer
buffs use to refer to information passed from one function to another.)
In short, the following function header states that the main() function returns an integer
value to the function that calls it and that main() takes no information from the function
that calls it:
int main(void) ====== int main(int agrc,char* agrv[]) char *argv[ ]实际上就是一个字符串二维数组,
在main()函数传参中,数组的传参,calling function传给called function是数组时,并非传递整个整个字符串二维数组过去,而是传递了一个指针是指向字符串指针数组的。
参考百度上的代码
#include <stdio.h>//#包含<stdio.h> int main(int argc,char* argv[])//整数类型主函数(整数类型统计参数个数,字符类型*数组指针至字符[]){ printf("%d\n",argc);//格式化输出 while(argc)//当(统计参数个数) printf("%s\n",argv[--argc]);//格式化输出 return 0;//返回0;正常退出}
得到如图