个人学习:main()函数

C primer plus:   


Consider the interface description for main(), beginning with the int part.A C++

function called by another function can return a value to the activating (calling) function.
That value is called a return value. In this case, main() can return an integer value, as indicated
by the keyword int. Next, note the empty parentheses. In general, a C++ function
can pass information to another function when it calls that function.The portion of the
function header enclosed in parentheses describes that information. In this case, the empty
parentheses mean that the main() function takes no information, or in the usual terminology,
main() takes no arguments. (To say that main() takes no arguments doesn’t mean
that main() is an unreasonable, authoritarian function. Instead, argument is the term computer
buffs use to refer to information passed from one function to another.)
In short, the following function header states that the main() function returns an integer
value to the function that calls it and that main() takes no information from the function

that calls it:


int main(void)     ====== int main(int agrc,char* agrv[])   char *argv[ ]实际上就是一个字符串二维数组,

在main()函数传参中,数组的传参,calling function传给called function是数组时,并非传递整个整个字符串二维数组过去,而是传递了一个指针是指向字符串指针数组的。

参考百度上的代码

#include <stdio.h>//#包含<stdio.h> int main(int argc,char* argv[])//整数类型主函数(整数类型统计参数个数,字符类型*数组指针至字符[]){ printf("%d\n",argc);//格式化输出 while(argc)//当(统计参数个数) printf("%s\n",argv[--argc]);//格式化输出 return 0;//返回0;正常退出}


得到如图


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值