About command line arguments of main function

后端 未结 4 1361
暗喜
暗喜 2020-12-19 07:44

It will look like int main(int argc, char *argv[]);. My questions are:

1 How many array items can I add in argv[]?

2 What is MAX si

4条回答
  •  清酒与你
    2020-12-19 08:24

    I think you're misunderstanding what's going on here. You don't, in your code, add anything to argv[], and you don't worry about their maximum sizes. When somebody runs your compiled program, as

    ./javas_program argument1 argument2 argument3
    

    then your main function will be called. argc will be 4, argv[0] will be ./javas_program, argv[1] will be argument1, argv[2] will be argument2, etc.

    In your program, you should assume that the contents of argv[] can be any size. If you want to limit them to a specific size, you should check that they're not larger than that.

提交回复
热议问题