1.区别typedef与#define
(1)/#define INITSIZE 10
//宏常量 预编译阶段 字符串(宏)替换
(2)//typedef -> 类型的重定义(3)具体区别
#define INT_Pointer int* ///INT_Pointer a, b; //int *a , b
define只能是宏定义,不能重定义类型
typedef可以重定义类型
typedef int* INT_POINTER;
INT_POINTER a, b;//等同于int*a;int*b;
2.typedef的应用
(1)typedef 定义数组类型
注意:可以先进行类型的定义再在定义的前方加上typedef进行类型的重定义(更好理解一些)
//typedef int Arr[10];
//typedef unsigned long long uint64_array[10];
(2)typedef 定义指针类型
typedef unsigned long long* uint64_pointer;
(3)
//#define INT_Pointer int* ///INT_Pointer a, b; //int *a , b
(4)定义相同类型的多个变量//想要定义相同类型的多个变量typedef int* INT_POINTER; int main() { INT_POINTER a, b;//等同于int*a;int*b; int temp; a = &temp; b = &temp;
(5)typedef 的应用
typedef unsigned long long uint64;//unsigned是无符号的意思 typedef unsigned int uint32; typedef unsigned char uint8; typedef unsigned short uint16; //typedef 定义数组类型 typedef int Arr[10]; typedef unsigned long long uint64_array[10]; int arr[10] = {1,2,3,4,5,6,7,8,9,10}; uint64 temp = 10; uint64_pointer p = &temp; Arr arr = { 1,2,3,4,5,6,7,8,9,10}; uint64_array brr = {1,2,3,4,5,6,7,8,9,0}; uint64 a = 10; uint64 b = 20; uint64 c = 30; for (uint64 i = 0; i < 10; i++) { uint64 res = 1; } uint8 d = 100; uint16 e = 100; //}
区别typedef与#define
最新推荐文章于 2025-04-20 21:14:22 发布