对 main 的 argc argv有点困惑 写了实验代码
#include <stdlib.h> #include <stdio.h> int main( int argc, char** argv ) { int i = 0; for ( ; i < argc; i++ ) { printf( "argv[%d] is %s\n", i, argv[i] ); } int arg_c = argc; char** arg_v = argv; arg_c--, arg_v++; while (arg_c > 0 && *arg_v[0] == '-') { while (*++arg_v[0]) { switch (*arg_v[0]) { case 'v': printf("v\n"); break; case 'q': printf("q\n"); break; case 'f': printf("f\n"); break; default: break; } //argc--, av++; } arg_c--, arg_v++; } for ( i = 0 ; i < argc; i++ ) { printf( "argv[%d] is %s\n", i, argv[i] ); } printf( "size of 4 is %d and null is %d\n", sizeof(argv[4]), sizeof('\0')); exit(0); }