标签:byte tom star 定义 return 基本数据类型 lin tar 理解
数据类型可以理解为固定内存大小的别名
数据类型是创建变量的模子
变量是一段(具体)连续存储空间的别名
程序通过变量申请并命名存储空间
通过变量名可以使用存储空间
(1)类型与变量的关系
#include <stdio.h>
int main()
{
char c = 0;
short s = 0;
int i = 0;
printf("sizeof(char) = %d, sizeof(c) = %d\n", sizeof(char), sizeof(c));
printf("sizeof(short) = %d, sizeof(s) = %d\n", sizeof(short), sizeof(s));
printf("sizeof(int) = %d, sizeof(i) = %d\n", sizeof(int), sizeof(i));
return 0;
}
输出结果为:
(2)自定义类型与创建变量
#include <stdio.h>
typedef int INT32;
typedef unsigned char BYTE;
typedef struct _tag_ts
{
BYTE b1;
BYTE b2;
short s;
INT32 i;
} TS;
int main()
{
INT32 i32;
BYTE b;
TS ts;
printf("%d, %d\n", sizeof(INT32), sizeof(i32));
printf("%d, %d\n", sizeof(BYTE), sizeof(b));
printf("%d, %d\n", sizeof(TS), sizeof(ts));
return 0;
}
输出结果为:
<wiz_tmp_tag id="wiz-table-range-border" contenteditable="false" style="display: none;">
标签:byte tom star 定义 return 基本数据类型 lin tar 理解
原文地址:https://www.cnblogs.com/chen-ace/p/9838161.html