开发者

Struct in a struct

开发者 https://www.devze.com 2023-01-29 03:54 出处:网络
Is this usage suitable, and what does it mean? struct Taken { int *p; 开发者_如何学Cstruct Taken *previous;

Is this usage suitable, and what does it mean?

struct Taken
{
int *p;
开发者_如何学Cstruct Taken *previous;
};


It's probably a linked list, but it's not a struct in a struct, it's a pointer to a struct.


struct Taken *previous;

This line declares previous to be a pointer to another structure of the same type Taken -- this can be used to chain together several such structures, for example, to form a linked list. If you're not familiar with this kind of usage, you should probably read up on pointers and their applications.


Yes, that is the typical data structure for a linked list. A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains a reference (i.e., a link) to the next/previous record in the sequence

http://en.wikipedia.org/wiki/Linked_list


Yes, it's a suitable usage and what you're looking at is most likely a node in some sort of linked list.


It means that previous is a pointer to a Taken struct. Yes, it is valid.


This is the standard element that is used in a linked list.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号