您的位置:首页 > 其它

malloc函数

2018-03-17 17:32 197 查看
如:char *Ptr = NULL;Ptr = (char *)malloc(100 * sizeof(char));
左侧括号里要做强制类型转换,与*号有关,右边sizeof则不是了typedef int datatype;
struct Node;
typedef struct Node *PNode;
struct Node
{
datatype data;
PNode link;
};

struct ClinkQueue
{
PNode r;
};

typedef struct ClinkQueue *PClinkQueue;

PClinkQueue createQueue()
{
PClinkQueue q = (PClinkQueue)malloc(sizeof(ClinkQueue));
q->r = NULL;
return q;
}

void inQueue(PClinkQueue q,datatype x)
{
PNode p;
p = (PNode)malloc(sizeof(struct Node));
这两段代码malloc函数左侧括号里都是指针,右侧是对应该变量。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: