Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>-You need to use double pointer since you need to change the pointer to your struct and call by reference is not allowed in C.</p> <p>-It would not work with a single pointer. Because you want to change the pointer to your object. You do it by the statement <code>*currItem = (*currItem)-&gt;next;</code> In order to change it permanently, you need to use a pointer to it. Which makes you use double pointer.</p> <p>Think of it that way:</p> <p>you have an integer variable <code>a</code> that you want a function to change its value. You simply call this function with a pointer to the variable <code>a</code> like:</p> <pre><code>void changeTheValue(int *x) { *x = 7; } void main() { int a = 5; changeTheValue(&amp;a); } </code></pre> <p>and in your case you want to change your <em>pointer's</em> value and you simply pass its pointer to the function.(double pointer) simple as that. <strong>If you want to change value of something with a function, then you have to pass its pointer to the function.</strong></p> <p>-When you make a call to malloc, you want space from it. And you state that you want a space as big as the size of your struct. (Like when you did in here <code>list = (struct item*) malloc(sizeof(struct item));</code>) and malloc allocates a space as big as your struct. If size of your struct is 1 byte then you have a 1 byte space, if it is 4, then you have consecutive 4 bytes. See, this is how your struct is kept in the memory. If you declare a struct variable or an array etc. then your struct is kept in memory like (dunno if it is a good metaphor) an array. The first member comes first, and then the second...</p> <p>say if you have a struct</p> <pre><code>struct myStruct { int a; float b; char c; }; </code></pre> <p>then the memory looks like</p> <hr> <p>a</p> <hr> <p>b</p> <hr> <p>c</p> <p>ps: you are making an illegal call to free on the line <code>free(intTemp);</code> you are *free*ing a variable that you didn't *malloc*ed.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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