1.1 数据类型和变量
1.1.1 啥是数据类型
- 数据类型是一种模子(可以类似于打蜂窝煤 的那个机器)
- 数据类型是固定内存大小的别名
- 数据类型只是一种模子,并不会实际的占用内存空间,只有当用
模子
(数据类型
)定义变量的时候才会占用空间。
1.1.2 变量
- 变量是一段实际连续存储空间的别名
- 程序中通过变量来申请并命名存储空间
- 通过变量的名字可以使用存储空间
注意:sizeof是操作符,不是函数;sizeof测量的实体大小为编译期间就已确定
1.1.3 举例
int main()
{
int a = 10;
int b[10] ;
printf("int a:%d \n", sizeof(a));
printf("int a:%d \n", sizeof(int *));
printf("int b:%d \n", sizeof(b));
printf("int b:%d \n", sizeof(b[0]));
printf("int b:%d \n", sizeof(*b));
printf("hello.....\n");
return 0;
}
1.2 数据类型的封装
1.2.1 封装1
- 封装换种解释就是重命名。
//像C库函数中的类型一般都是这样进行命名的。
typedef unsigned int size_t;
typedef unsigned int uint32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
1.2.2 封装2
- 对void* ,void** 进行封装。
typedef void ** handle;
typedef void * handle;
1.2.3 封装3
- 使用 struct
typedef struct Teacher{
char name[10];
int age;
}Teaacher ;
参考一 : 狄泰软件课程
如有侵权:请联系邮箱 1986005934@qq.com