哪些参数的main()呢? [英] What are the arguments to main() for?

查看:160
本文介绍了哪些参数的main()呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我创建一个项目(标准命令行实用程序)与X code,我
主要功能开始出去找这样的:

Everytime I create a project (standard command line utility) with Xcode, my main function starts out looking like this:

int main(int argc, const char * argv[])

这是什么都在括号?为什么用这个,而不是仅仅
INT的main()

推荐答案

主要接收的参数传递给它的参数的个数,当你启动程序,这样你就可以访问它。

main receives the number of arguments and the arguments passed to it when you start the program, so you can access it.

ARGC包含了参数的个数,argv的包含指向的参数。
ARGV [ARGC]始终是一个空指针。这些参数通常包括节目名称本身。

argc contains the number of arguments, argv contains pointers to the arguments. argv[argc] is always a NULL pointer. The arguments usually include the program name itself.

通常情况下,如果你运行你的程序,比如 ./ myprogram

Typically if you run your program like ./myprogram


  • ARGC为1;

  • 的argv [0]是字符串./myprogram

  • 的argv [1]是一个空指针

如果你运行你的程序,比如 ./ myprogram的/ tmp / somefile

If you run your program like ./myprogram /tmp/somefile


  • ARGC为2;

  • 的argv [0]是字符串./myprogram

  • 的argv [1]是字符串/ tmp目录/ somefile

  • 的argv [2]是一个空指针

这篇关于哪些参数的main()呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆