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

时间:2023-03-09 19:30:47
在函数体的“出口处”,对 return 语句的正确性和效率进行检查

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

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

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

 #include <iostream>
#include <time.h> using namespace std; //main()函数的定义 int main(int argc, char** argv) {
//声明time_t类型的变量,其以秒为单位存放系统时间
time_t current_time; //得到当前的系统时间(秒)
time(&current_time); //转换系统时间为tm结构的时间信息
tm *ptime=gmtime(&current_time); //显示time_t结构的时间
cout<<"current_time:"<<current_time<<endl; //显示tm结构的时间信息
cout<<"seconds after the minute:"<<(ptime->tm_sec)<<endl;
cout<<"minutes after the hour:"<<(ptime->tm_min)<<endl;
cout<<"hours since midnight:"<<(ptime->tm_hour)<<endl;
cout<<"day of the month:"<<(ptime->tm_mday)<<endl;
cout<<"months since January:"<<(ptime->tm_mon)<<endl;
cout<<"years since 1900:"<<(ptime->tm_year)<<endl;
cout<<"days since Sunday:"<<(ptime->tm_wday)<<endl;
cout<<"days since January 1:"<<(ptime->tm_yday)<<endl;
cout<<"daylight savings time flag:"<<(ptime->tm_isdst)<<endl;
}