【发布时间】:2014-05-30 20:52:46
【问题描述】:
我不太明白指向指针的指针是如何工作的。有什么方法可以在不使用指针的情况下完成相同的工作?
struct customer
{
char name[20];
char surname[20];
int code;
float money;
};
typedef struct customer customer;
void inserts(customer **tmp)
{
*tmp = (customer *)malloc(sizeof(customer));
puts("Give me a customer name, surname code and money");
scanf("%s %s %d %f", (*tmp)->name, (*tmp)->surname, &(*tmp)->code, &(*tmp)->money);
}
【问题讨论】:
-
OT:不要转换 malloc 的结果:stackoverflow.com/questions/605845/…
-
你可以在函数中创建
customer* tmp并返回指针而不是void。 -
指针是一个变量,它告诉您在哪里可以找到另一个变量。如果您了解“指向变量的指针”的概念,那么您必须了解“指向指针的指针”,因为这是它的一种特殊情况。