本文介绍了如何使用指针和malloc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hai
我的任务是使用单个指针在链表中创建队列..
我想知道如何在指针struct下使用malloc ...
hai
my task is using a single pointer to creat a queue in linkedlist..
i want to know how to use malloc under pointer struct...
推荐答案
object* objectPointer = (object*)malloc(sizeof *objectPointer);
objectPointer->nextObject = NULL;
这样就可以得到一个地址保存在指针中的对象.将指针存储到该对象中的下一个对象(在上面放置了NULL),然后根据需要重复进行操作,您便拥有了链表.
That gets you one object whose address is saved in a pointer. Store a pointer to the next object in that one (where I put NULL above), and repeat as necessary and you have your linked list.
这篇关于如何使用指针和malloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!