I queue in C. I have a structure like:
struct Node { Node* next; Node* previous; // data }
Because nextand previousare just pointers, whether the value of importance is, if I use Node*or int*? eg:
next
previous
Node*
int*
struct Node { int* next; int* previous; // data }
Use int *is incorrect and leads to undefined behavior. You can use either Node *, or void *, but if you are using a type other than Node *, it will require re-translation (or implicit conversion, for example, through an assignment), before Node *you can dereference it.
int *
Node *
void *
( , ), , . 1 Node * sizeof (Node) , == sizeof (int).
, , ( ), .
, . Node int (Node , int), int Node .
Node
int
.
, , , , , C .
, , casted-type .
struct Node { struct Node* next; struct Node* previous; // data };
int *, , , Node *, , node.
The difference is the size of the pointed space with a pointer. When it is int *, the ++ pointer shifts the sizeof (Node) pointer, and with its Node *, the ++ pointer shifts the sizeof (Node) pointer.
If there is
Node * pNode;
the expectation is to be able to write expressions like the following without any cast
(*pNode).next = ... pNode->next = ...
Source: https://habr.com/ru/post/1765920/More articles:Does this number have more than ten decimal places? - cCould not find implicit value for ordering parameters - scalaUsing soundsc in Octave, on Windows 7 - octaveNesting fonts forces Silverlight to always rebuild - fontsSymfony: как фильтровать данные на интерфейсе, как в бэкэнд - phpopen pdf from asp.net page - asp.netWhat to include exceptions in catch clause - javaNetbeans or Eclipse? - eclipseQuestion about SolrNet Faceting - solrGood user interface design: how to handle an empty ListView? - javaAll Articles