C++-数据类型

C++ 数据类型

int\float\double的最值

  • 引用limits
#include <limits>

代码

    cout << "INT_MIN is " << INT_MIN << endl;
    cout << "INT_MAX is " << INT_MAX << endl;
    cout << "LONG_MIN is " << LONG_MIN << endl;
    cout << "LONG_MAX is " << LONG_MAX << endl;
    cout << "FLT_MIN is " << FLT_MIN << endl;
    cout << "FLT_MAX is " << FLT_MAX << endl;
    cout << "DBL_MIN is " << DBL_MIN << endl;
    cout << "DBL_MAX is " << DBL_MAX << endl;

结果

INT_MAX is 2147483647
LONG_MIN is -2147483648
LONG_MAX is 2147483647
FLT_MIN is 1.17549e-038
FLT_MAX is 3.40282e+038
DBL_MIN is 2.22507e-308
DBL_MAX is 1.79769e+308

float\double\int\long所占字节数

    cout << "float = " << sizeof(float) << endl;
    cout << "double = " << sizeof(double) << endl;
    cout << "int = " << sizeof(int) << endl;
    cout << "long = " << sizeof(long) << endl;

结果

float = 4
double = 8
int = 4
long = 4

c++的pow函数

  • 引用cmath包

代码

# include <iostream>
# include <cmath>
using namespace std;
int main()
{
    cout <<pow(2,3)<<endl;
}

c++的time(0)函数

  • 作用:或者系统当前时间(GMT时区)

代码

#include <iostream>
using namespace std;
int main()
{
    int allSeconds = time(0);
    int currentSecond = allSeconds % 60;
    int allMinutes = allSeconds / 60;
    int currentMinute = allMinutes % 60;
    int allHours = allMinutes / 60;
    int currentHour = allHours % 24;

    cout << currentSecond << endl;
    cout << currentMinute << endl;
    cout << currentHour << endl;
}

结果

当前秒:24
当前分:1
当前时:8
posted @ 2022-06-28 16:03  梧桐灯下江楚滢  阅读(59)  评论(0)    收藏  举报