main函数返回值作用

转贴:http://topic.csdn.net/t/20060915/10/5023777.html

(hailongchang)下面是一个国外新闻组上的讨论,我认为讲的非常清楚,lz可以看看 

Typically   the   return   value   is   used   as   a   exit   status   code   (I   prefer   to   use   the   exit   ()   function   myself).   So   that,   if   your   program   is   called   by   another   program   or   a   shell/batch   script,   the   calling   entity   can   react   to   the   exit   status   appropriately. 

To   explain   this   a   little   more   clearly,   assume   your   program   parses   a   large   file   and   inserts   the   parsed   data   into   a   database.   Your   program   is   called   by   a   user   clicking   a   button   in   some   other   program.   How   does   the   user   know   if   your   program   successfully   completed   the   task?   Or,   if   it   was   not   completed   successfully,   why?   

The   easiest   way   to   tell   what   happened   after   your   program   has   completed   is   to   check   the   returned   exit   status   code.   Most   of   the   time   these   codes   are   defined   by   you.   For   instance,   0   if   it   completed   okay,   1   if   it   could   not   connect   to   the   database,   2   if   it   deadlocked   with   another   user   in   the   database,   3   if   it   couldn 't   find   the   file   to   parse,   etc.   Then,   using   these   codes,   the   calling   program   can   print   the   appropriate   message   to   the   user 's   screen,   or   use   some   sort   of   logic   that   will   attempt   to   get   your   program   to   complete   successfully.

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值