Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The "->" is meant to access an element in a structure that is dynamically allocated and "." is used to access an element in a structure that is statically allocated.</p> <p>Here is an example:</p> <pre><code>typedef struct product_data product_data; struct product_data { int product_code; int product_size; product_data *next; }; product_data *products_head = NULL; product_data *products_tail = NULL; int main() { /* Allocate memory */ product_data *newproduct = malloc(sizeof(product_data)); int newcode = 5; int newsize = 5; products_head = newproduct; newproduct-&gt;product_size = newsize; newproduct-&gt;next = NULL; /* free memory */ free(product_data); return 0; } </code></pre> <p>But remember that for all the new nodes that you make in the linked list you will have to allocate memory and free that memory. A good program to use to check that all the memory you allocated was free'd is valgrind. And if you run into logic errors trying to make the linked list draw it out by hand first like this:</p> <pre><code> [head] [tail] | | V V [ a ] -&gt; [ b ] -&gt; null </code></pre> <p>Just remember that head and tail are both pointers (so they do not need to be allocated memory, they just need to be POINTING at the node that you want.</p> <p>If you still run into problems because your logic gets very complicated I sugget you try and learn GDB (it is a command line debugger) it will help you step through your code so you can see what is happening step by step. That is how I first learnt to create data structure.</p> <p>Good Luck!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload