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;
都是一样的。