字节大小

C++ 今日笔记

1:字节大小
Visual c++6.0中int、short、long型所占用字节情况如下:

char 1字节
short 2字节
int 4字节
long 4字节
bool 1字节
char 的范围是-128–127;

用VS编辑如下:
**#include “stdafx.h”
**#include
using namespace std;
int main()
{
cout << sizeof(char) << endl;
cout << sizeof(short) << endl;
cout << sizeof(int) << endl;
cout << sizeof(float) << endl;
cout << sizeof(long) << endl;
cout << sizeof(double) << endl;
cout << sizeof(bool) << endl;
return 0;
}
输出的结果:
1
2
4
4
4
8
1

2:不同指向类型的指针的内存大小是一样的:
在win32平台上,都是4位 ;
在win64平台上,都是8位;
如下:
int *p1=new int ;
double *p2=new double;
那么:
sizeof(p1)=4;
sizeof(p2)=4;
都是一样的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值