C ++程序在您的系统中查找int,float,double和char的大小
C++中的数据类型
C++中有许多数据类型,但最常用的是int,float,double和char。关于这些数据类型的一些细节如下-
int-用于整数数据类型,通常需要4个字节的存储空间。
float-用于存储单精度浮点值或十进制值。浮点变量通常需要4个字节的存储空间。
double-用于存储双精度浮点值或十进制值。双变量通常需要8个字节的存储空间。
char-用于存储字符。字符通常需要1字节的存储空间。
C++中的sizeof运算符
sizeof运算符用于查找数据类型的大小。它是一个编译时运算符,用于确定不同变量和数据类型的大小(以字节为单位)。sizeof运算符的语法如下-
sizeof (data type);
查找int,float,double和char大小的程序如下-
示例
#include <iostream>
using namespace std;
int main() {
cout<<"Size of int is "<<sizeof(int)<<" bytes"<<endl;
cout<<"Size of float is "<<sizeof(float)<<" bytes"<<endl;
cout<<"Size of double is "<<sizeof(double)<<" bytes"<<endl;
cout<<"Size of char is "<<sizeof(char)<<" byte"<<endl;
return 0;
}输出结果
Size of int is 4 bytes Size of float is 4 bytes Size of double is 8 bytes Size of char is 1 byte
在上面的程序中,sizeof运算符用于查找int,float,double和char的大小。这是使用cout对象显示的。
cout<<"Size of int is "<<sizeof(int)<<" bytes"<<endl; cout<<"Size of float is "<<sizeof(float)<<" bytes"<<endl; cout<<"Size of double is "<<sizeof(double)<<" bytes"<<endl; cout<<"Size of char is "<<sizeof(char)<<" byte"<<endl;
热门推荐
7 聚餐会祝福语简短
9 初八祝福语简短语
10 带清的简短祝福语
11 国庆中秋祝福语简短搞笑
12 老师送的祝福语简短
13 圣诞祝福语简短文字
14 18岁祝福语搞笑简短
15 爱情祝福语大全 简短实际
16 怎么生孩子祝福语简短
17 给侄子祝福语简短精辟
18 特别的端午祝福语简短