20240000 嵌入式八股
明昧 Lv7

数据所在内存大小

image-20240627120955414

double 8

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

char ch[]={“zhang”};

sizeof(ch)=6

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

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

1
2
3
4
5
6
7
8
9
10
11
 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 联合具体情况而定。

 Comments
Comment plugin failed to load
Loading comment plugin
Powered by Hexo & Theme Keep
Unique Visitor Page View