具体代码如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#include<stdio.h> void main() { //使用sizeof验证数据类型在内存中占用的空间大小 // char // int // short // long // unsigned int // float // double // long double printf ( "在64位机器中:\n" ); printf ( " char类型占%d个字节\n" , sizeof ( char )); printf ( " short类型占%d个字节\n" , sizeof ( short )); printf ( " int类型占%d个字节\n" , sizeof ( int )); printf ( " long类型占%d个字节\n" , sizeof ( long )); printf ( "unsigned int类型占%d个字节\n" , sizeof (unsigned int )); printf ( " float类型占%d个字节\n" , sizeof ( float )); printf ( " double类型占%d个字节\n" , sizeof ( double )); printf ( " long double类型占%d个字节\n" , sizeof ( long double )); printf ( "-------------------指针占4个字节---------------------\n" ); char *p0; short *p1; int *p2; long *p3; unsigned int *p4; float *p5; double *p6; long double *p7; printf ( " char类型指针占%d个字节\n" , sizeof (p0)); printf ( " short类型指针占%d个字节\n" , sizeof (p1)); printf ( " int类型指针占%d个字节\n" , sizeof (p2)); printf ( " long类型指针占%d个字节\n" , sizeof (p3)); printf ( "unsigned int类型指针占%d个字节\n" , sizeof (p4)); printf ( " float类型指针占%d个字节\n" , sizeof (p5)); printf ( " double类型指针占%d个字节\n" , sizeof (p6)); printf ( " long double类型指针占%d个字节\n" , sizeof (p7)); } |
结果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
在64位机器中: char 类型占1个字节 short 类型占2个字节 int 类型占4个字节 long 类型占4个字节 unsigned int 类型占4个字节 float 类型占4个字节 double 类型占8个字节 long double 类型占12个字节 -------------------指针占4个字节--------------------- char 类型指针占4个字节 short 类型指针占4个字节 int 类型指针占4个字节 long 类型指针占4个字节 unsigned int 类型指针占4个字节 float 类型指针占4个字节 double 类型指针占4个字节 long double 类型指针占4个字节 |
知识点扩展:
c语言实现十进制与ASCII码互转
1
2
3
4
5
|
//十进制转ASCII码 //年#define KB2ASC(x) (u8)(0x30+x) //ASCII码转十进制 //年 #define ASC2KB(x) (u8)(x%(0x30)) |
总结
以上所述是小编给大家介绍的C语言实现 数据类型占多少字节指针占多少字节,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
原文链接:https://blog.csdn.net/qq_21808961/article/details/78107080