C语言基础:结构体及指针使用范例
#include <stdio.h>
#include <alloc.h>
int main(void)
{
int i;
struct ListEntry {
int number;
struct ListEntry *next;
} start, *node;
start.next = NULL; // Empty list
node = // Point to the start of the list
for (i = 1; i <= 10; i++)
{
node->next = (struct ListEntry *) malloc(sizeof(struct ListEntry));
node = node->next;
node->number = i;
node->next = NULL;
}
// Display the list
node = start.next;
while (node)
{
printf("%d ", node->number);
node = node->next;
}
return 1;
}
运行结果
1 2 3 4 5 6 7 8 9 10
