Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>As mvp reply</strong> <code>it is correct answer but i am here just explaining something, which will help you to understand, why your code is not working.</code> <hr> <strong>First let me explain operator you used</strong><br> <strong>1] Ampersand Operator (&amp;)</strong><br> <code>This operator helps you to get reference/address of variable</code><br> As soon as we declare a variable, the amount of memory needed is assigned for it at a specific location in memory, As we generally do not actively decide the exact location of the variable within the operating system during run time but some time we need to know address of our variable like here <code>You want to know the address of variable to assign it's address to pointer</code> The address that locates a variable withing memory is what we call a <code>reference</code> to that variable Which we can get using Reference variable.<br></p> <p><strong>Dereference Operator (*)</strong><br> As we know that pointer is the variable which will store that address of the another variale, using pointer we can directly access the value stored in the variable which it points.<code>To do this we simply have to precede the pointer's identifier with an asterisk (*), which acts as deference operator and that can be literally translated to value pointed by</code> <hr> <strong>Now back to your code</strong></p> <pre><code>function2(int *hello) { // Here you create function that accept address of variable (You will get address of hello pointer 101 NOT 100 of variable assign in your MAIN) //something } function1(int *hello) {// Here you create function that accept address of variable (Here it will get address of hello which is 100) function2(&amp;hello); // Here you again pass address of your pointer hello (Which may be 101) [BAD] } main { int hello = 0; // Let say it's address is 100 function1(&amp;hello); // Here you pass address of your variable(which is 100) [GOOD] } </code></pre> <p><hr> <strong>Solution is as suggested</strong> <Br></p> <pre><code> function2(int *hello) { //Change your value here *hello = 123; } function1(int *hello) { function2(hello); // It will pass 100 (address of your variable hello assign in MAIN } main { int hello = 0; function1(&amp;hello); } </code></pre>
 

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