# define typedef用法

#define

#define MUL1(x)  x * x
#define MUL2(x)  (x) * (x)

MUL1(3)         // 9
MUL1(3+2)       // 3+2*3+2 = 11
MUL2(3)         // 9
MUL2(3+2)       // (3+2)*(3+2) = 25

#define SUB(x,y) x-y
#define ACCESS_BEFORE(element,offset,value)     *(SUB(&element, offset)) = value
void main_5()
{
int array[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int i;
ACCESS_BEFORE(array[5], 4, 99);// *SUB(&array[5], 4) = 99
// * (&array[5] - 4) = 99
printf("array: ");
for (i = 0; i < 10; ++i) {
printf("%d", array[i]);
}
printf("\n");

typedef

typedef unsigned int uint8_t;
typedef char* p_CHAR;

uint8_t time;
p_CHAR pa, pb; // 定义两个char型指针，不同于char *pa, pb

//
struct point{
int x;
int y;
};
typedef struct point Point;

//
typedef struct area{
int weight;
int hight;
}Area, *p_area; // 此处：Area* p_area

//
typedef struct {
string name;
int age;
}Person;

struct point my_point1 = {4, 5};
Point my_point2 = {6,7};
Area my_area1 = {2, 6};
Person my_person1 = {"mr-xuf", 24};

cout << "my_point1 x = " << my_point1.x << ", my_point1 y = " << my_point1.y <<endl;
cout << "my_point2 x = " << my_point2.x << ", my_point2 y = " << my_point2.y <<endl;
cout << "my_area1 weight = " << my_area1.weight << ", my_area1 hight = " << my_area1.hight <<endl;
cout << "my_person1 name = " << my_person1.name << ", my_person1 age = " << my_person1.age <<endl;

typedef int arr_t[5];///定义了一个数组类型arr_t，该类型的变量是个数组
int main(void)
{
arr_t d;        //d是个数组，这一行等价于:  int d[5];
arr_t b1, b2, b3;//b1, b2, b3都是 包含5个元素的数组

d[0] = 1;
d[1] = 2;
d[4] = 134;
d[5] = 253;//编译警告：下标越界
}

typedef int(*pArr_t)[5];//定义一个指针类型，该类型的指针可以指向含5个int元素的一维数组

int main(void)
{
int a[5] = {1,2,3,4,5};
int b[7] = {1,2,3,4,5,6，7};
pArr_t pA;//定义数组指针变量pA
pA= &a;//完全合法，无警告
pA= (pArr_t)&b;//类型强制转换为pArr_t，完全合法，无警告
}

typedef int (my_f)(int, int);
cout << "add function...." << a + b << endl;
return a + b;
}
pp(7, 8);

typedef int(*my_func)(int , int );// 声明指针my_func 指向int(*)(int, int)
cout << "add function...." << a + b << endl;
return a + b;
}

int (*p)(int , int);// 定义变量p 指向一个xxxx函数
p(1, 5);

03-19 177

01-11 518

09-29 4710

10-05 313

04-07 501

07-03 2867

09-28 1653

04-15 543

01-04 335

12-03 71

06-04 8万+

12-12 11万+

12-21 902

04-14 61万+

03-13 15万+

03-12 2667

02-28 1万+

03-01 14万+

03-08 1万+

#### win10暴力查看wifi密码

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客