typedef,后加指针,数组等
2017-08-29 11:55
218 查看
很简单,定义一个指针。它的类型和struct相关。如果typedef后面有多个定义,我们可以逐个拆开。
typedef int *PInt, Int, **PPInt;
我们可以拆成:
// typedef int *PInt;
// typedef int **PPInt;
// typedef int Int;
typedef 后还可以跟数组:
typedef int IntArramy[10];
IntArray array;
typedef int *PInt, Int, **PPInt;
我们可以拆成:
// typedef int *PInt;
// typedef int **PPInt;
// typedef int Int;
#include <stdio.h> #include <stdlib.h> #include <string.h> void test_typedef_p(); void test_typedef_normal(); int main(int argc, char *argv[]) { test_typedef_p(); test_typedef_normal(); return 0; } void test_typedef_normal(){ typedef int *PInt, Int, **PPInt; // typedef int *PInt; // typedef int **PPInt; // typedef int Int; Int a=1; PInt pint_a = &a; PPInt ppint_a=&pint_a; printf("ppinta:= %d \n", **ppint_a); } void test_typedef_p(){ #if 0 struct node { int data; struct node *next; } *head =NULL; #else typedef struct node { int data; struct node *next; } *NodePtr, Node, *NodePer2; Node *head =NULL; #endif head =(struct node*)malloc(sizeof(struct node)); memset(head, 0, sizeof(struct node)); head->data=1; head->next=NULL; printf(" head data is: %d \n ", head->data); NodePtr pointer_str; pointer_str =(struct node*)malloc(sizeof(struct node)); memset(pointer_str, 0, sizeof(struct node)); pointer_str->data=1; pointer_str->next=NULL; printf("pointer_str data is: %d \n ", pointer_str->data); NodePtr pointer_str2; pointer_str2 =(Node*)malloc(sizeof(Node)); memset(pointer_str2, 0, sizeof(Node)); pointer_str2->data=1; pointer_str2->next=NULL; printf("pointer_str2 data is: %d \n ", pointer_str2->data); // const NodePtr p3; // p3 = pointer_str2; const NodePtr p3 = pointer_str2; //p3 =(Node*)malloc(sizeof(Node)); memset(p3, 0, sizeof(Node)); p3->data=2; p3->next=NULL; printf("p3 data is: %d \n ", p3->data); }
typedef 后还可以跟数组:
typedef int IntArramy[10];
IntArray array;
相关文章推荐
- C++ primer(七)--函数、C++的编程模块 函数指针 函数指针数组 typedef
- typedef 还可以掩饰复合类型,如指针和数组
- 指针、枚举、数组、typedef、内联函数、define、extern、static变量
- typedef在数组、指针方面的应用
- C++(typedef、一维数组转成二维数组、C和C++区别、成员地址成员指针、构造析构函数、this指针、const用法、显示时间、const用法)
- 关于typedef,指针数组和数组指针,指针函数的说明
- 全局函数指针数组typedef和成员函数指针数组类内外部typedef
- 1、打印二进制机器码,程序内存分析,大端序小端序,指针数组,数组指针,数组的三种访问方式,typedef,#if-0-#endif,求数组大小,括号表达式
- 指针,函数,数组打杂混学习以及typedef学习笔记
- typedef 为数组和函数指针定义别名
- 多维数组 用typedef简化指针
- C++ 浅谈指针的用法:与const、一维数组、二维数组、typedef等结合
- typedef的学习 数组指针与指针数组的差异
- 25.数组指针和函数指针及typedef
- 关于C语言声明、指针、数组、函数、typedef等等的一通“超级扯”
- typedef 为数组和函数指针定义别名
- typedef 为数组和函数指针定义别名
- (学习日记)C++中用typedef来掩饰指针和数组
- C语言中的指针数组
- 指针数组和数组指针