sizeof()不是函数。

32位系统下:

bool    1(C没有bool类型)

char    1

short   2

int      4

long    4

float    4

double 8

sizeof(指针) 4 如:int* 4,char*4,double* 4。。。

char ch[]={"zhang"};    sizeof(ch)=6

 

1 void Func(char a[100])
2 {
3        cout<< sizeof(a)<<endl;//4字节,而不是100字节,数组退化为指针!《高质量C/C++编程7-3-3》
4 }

 

特别注意,类和结构体的大小(内存对齐和填充的概念),

 1 struct {
2 char c;
3 int i;
4 short s;
5 }str_1;
6
7 struct {
8 char c;
9 short s;
10 int i;
11 }str_2;

sizeof(str_1)=4+4+4=12;

sizeof(str_2)=4+4=8;

 

union 联合具体情况而定。

相关文章:

  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-08-01
  • 2021-10-13
  • 2021-08-13
猜你喜欢
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案