12 使用sizeof计算普通变量所占空间大小

(1)不同数据类型所占字节数不同(32位 64位系统不同)

int----->4

double----->8

char------->1

(2)代码

 1 #include<stdio.h>
 2 #include <stdlib.h>
 3 void Func(char str[100])
 4 {
 5     printf("sizeof(str)=%d\n", sizeof(str));
 6 }
 7 int main()
 8 {
 9     char str[] = "hello";
10     char *p = str;
11     int n = 10;
12     printf("sizeof(str)=%d\n", sizeof(str));//6
13     printf("sizeof(p)=%d\n", sizeof(p));//4
14     printf("sizeof(n)=%d\n", sizeof(n)); //4
15     void *pp = malloc(100);
16     printf("sizeof(pp)=%d\n", sizeof(pp));//4
17     Func(str);
18     getchar();
19 }
View Code

相关文章:

  • 2021-11-22
  • 2021-09-22
  • 2021-11-04
  • 2021-09-23
  • 2021-11-16
  • 2021-09-27
  • 2021-12-25
猜你喜欢
  • 2021-06-15
  • 2022-12-23
  • 2021-05-14
  • 2021-11-08
  • 2021-12-03
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案