C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ 程序在您的系统中查找 int、float、double 和 char 的大小

用于查找系统中 int、float、double 和 char 大小的 C++ 程序

该程序声明了 4 个类型为 int、float、double 和 char 的变量。然后,使用 sizeof 运算符评估每个变量的大小。
要查找变量的大小,请使用 sizeof 运算符。
sizeof(dataType);

示例: 查找变量的大小

#include <iostream>
using namespace std;
int main() 
{    
    cout << "Size of char: " << sizeof(char) << " byte" << endl;
    cout << "Size of int: " << sizeof(int) << " bytes" << endl;
    cout << "Size of float: " << sizeof(float) << " bytes" << endl;
    cout << "Size of double: " << sizeof(double) << " bytes" << endl;
    return 0;
}
输出
Size of char: 1 byte
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
注意: 如果您使用的是旧计算机,可能会得到不同的结果。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4