Can argc be zero on a POSIX system?

前端 未结 6 1390
暖寄归人
暖寄归人 2021-02-04 23:04

Given the standard definition for the main program:

int main(int argc, char *argv[]) {
   ...
}

Under which circumstances can argc

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-04 23:26

    whenever you want to run any executable like ./a.out it will have one argument thats the program name. But It is possible to run a program with argc as zero in Linux, by executing it from another program that calls execv with an empty argument list.

    for e.g

    int main() {
        char *buf[] = { NULL };
        execv("./exe", buf); /* exe is binary which it run with 0 argument */
        return 0;
    }
    

提交回复
热议问题