在函数体的“出口处”,对 return 语句的正确性和效率进行检查

在函数体的“出口处”,对 return 语句的正确性和效率进行检查。

如果函数有返回值,那么函数的“出口处”是 return 语句。

我们不要轻视 return 语 句。如果 return 语句写得不好,函数要么出错,要么效率低下。

 

 1 #include <iostream>
 2 #include <time.h>
 3 
 4 using namespace std;
 5 
 6 //main()函数的定义
 7 
 8 int main(int argc, char** argv) {
 9  //声明time_t类型的变量,其以秒为单位存放系统时间
10     time_t current_time;
11 
12     //得到当前的系统时间(秒)
13     time(&current_time); 
14 
15     //转换系统时间为tm结构的时间信息
16     tm  *ptime=gmtime(&current_time);
17 
18     //显示time_t结构的时间
19     cout<<"current_time:"<<current_time<<endl;
20 
21     //显示tm结构的时间信息
22     cout<<"seconds after the minute:"<<(ptime->tm_sec)<<endl;
23     cout<<"minutes after the hour:"<<(ptime->tm_min)<<endl; 
24     cout<<"hours since midnight:"<<(ptime->tm_hour)<<endl;  
25     cout<<"day of the month:"<<(ptime->tm_mday)<<endl;  
26     cout<<"months since January:"<<(ptime->tm_mon)<<endl; 
27     cout<<"years since 1900:"<<(ptime->tm_year)<<endl; 
28     cout<<"days since Sunday:"<<(ptime->tm_wday)<<endl; 
29     cout<<"days since January 1:"<<(ptime->tm_yday)<<endl; 
30     cout<<"daylight savings time flag:"<<(ptime->tm_isdst)<<endl;
31 }

 

转载于:https://www.cnblogs.com/borter/p/9413604.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值