我怎样才能让我的主要功能有返回什么? [英] How can I get what my main function has returned?
问题描述
在C程序中,如果我们想给从终端输入的一些话,我们可以给它:
In a C program if we want to give some input from terminal then we can give it by:
int main(int argc, char *argv[])
在以同样的方式,如果我们想获得的main()
函数的返回值那么怎样才能得到它呢?
In the same way, if we want to get return value of main()
function then how can we get it?
在每个的main()
我们写收益1
或返回0
;我怎么能知道我的的main()
在终端已经回来了?
In each main()
we write return 1
or return 0
; how can I know what my main()
has returned at terminal?
编辑:1
我得到它通过回声$?
我们可以得到的返回值的main()
,但只有它让我返回一个值小于125(在Linux中)成功。比这更返回值不能成功收到的 $变量
所以
I get it that by echo $?
we can get the return value of main()
but it only allows me to return a value less then 125 (in Linux) successfully. A return value more than that cannot be be successfully received by the $ variable
so
为什么 INT
的返回类型的main()
?为什么不把它短整型
?
why is int
the return type of main()
? Why not keep it short int
?
EDIT2
从哪里可以,如果找出错误code的含义的main()
返回一个值大于125?
From where can I find out the meaning of the error code if main()
returns a value greater than 125?
推荐答案
大部分炮弹存放previous运行命令的退出code在 $?
所以你可以存储或显示。
Most shells store the exit code of the previous run command in $?
so you can store or display it.
$ ./a.out
$ echo $? # note - after this command $? contains the exit code of echo!
或
$ ./a.out
$ exit_code=$? # save the exit code in another shell variable.
需要注意的是linux下的,虽然你返回 INT
,一般只值小于126的使用安全。较高的值被保留来记录尝试运行的命令或记录该信号,如果有的话,终止程序时可能发生的其他错误。
Note that under linux, although you return an int
, generally only values less than 126 are safe to use. Higher values are reserved to record other errors that might occur when attempting to run a command or to record which signal, if any, terminated your program.
这篇关于我怎样才能让我的主要功能有返回什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!