对于下列main函数,经过编译、连接后得到的可执行文件名为file.exe,并且已知在系统的命令状态下输入命令行“file Beijing Shanghai<回车>”后得到的输出结果是
Beijing
Shanghai
请在函数的空白处()填入合适的内容,使函数完整。
本题主要考察main()的参数问题。
The signature of main is:
int main(int argc, char **argv);
argc refers to the number of command line arguments passed in, which includes the actual name of the program, as invoked by the user. argv contains the actual arguments, starting with index 1. Index 0 is the program name.
So, if you ran your program like this:
./program hello world
Then:
argc would be 3.
argv[0] would be "./program".
argv[1] would be "hello".
argv[2] would be "world".
argc的值,也即是参数的个数,程序在运行时会自动统计,不必我们操心。