/*
# include< stdio.h >
# include< stdlib.h >
*/
#include <stdio.h>
#include <stdlib.h>
struct Node {
int Coefficient;
int Exponent;
struct Node *Next;
};
typedef struct Node PolyNode;
typedef struct Node *PtrToNode;
typedef PtrToNode Polynomial;
//void *InputPoly(struct Node *P);
void InputPoly(struct Node **P);
//void PrintPoly(struct Node *P);
int main() {
/*
PolyNode *Head; //声明一个表的头指针初始为NULL
Head = NULL;
*/
PolyNode *Head = NULL;
//printf("Head = %d\n", Head); //
printf("Head = %p\n", Head); //
//InputPoly(Head); //调用一个函数
InputPoly(&Head); //调用一个函数
//printf("Head = %d\n", Head); //
printf("Head = %p\n", Head); //
free(Head);
return 0;
}
//void *InputPoly(struct Node *P) //内存分配一个值
void InputPoly(struct Node **P) //内存分配一个值
{
struct Node *Ptemp;
Ptemp = (PolyNode *)malloc(sizeof(PolyNode));
//P = Ptemp;
*P = Ptemp;
//printf("P = %d\n", P);
printf("P = %p\n", P);
//P->Next = NULL;
(*P)->Next = NULL;
}
/*
调用函数给一个链表赋值,链表首地址NULL
调用的函数内部可以赋值但是不能传递地址给主函数
实在研究不出个所以然了,哪位大人可否帮忙修改,
还是要调用函数的方式,多谢m(_ _)m
运行结果
Head = 0
P = 5313264
Head = 0
Press any key to continue
*/
|