Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hope this helps</p> <pre><code> #include&lt;stdio.h&gt; void change(int *c)/*Pointer c now has the first location of the array a[]*/ { *(c+0) = 0;/*assign values to the array by adding step-size to the first array position*/ *(c+1) = 1; *(c+2) = 2; *(c+3) = 3; *(c+4) = 4; } main() { int a[5]={10,20,30,40,50}; /* Declare and Assign an array a[] of size 5.*/ int *b = a; /*Declare and assign a Pointer to the location of the array.*/ change(b); /*pass the pointer(which is now pointing to first position of array) to the change() function.*/ printf("%d,%d,%d,%d,%d,",a[0],a[1],a[2],a[3],a[4]);/*Print the changed value.*/ } </code></pre> <p>Output: 0,1,2,3,4,</p> <p>From Java point of view, Pointers are simply like(not exactly) Object references.</p> <pre><code>Object O; O = New SomeClassName(); </code></pre> <p>Like Object Reference O is pointing to some Actual Object of type SomeClassName, so does pointers in C:</p> <pre><code>int *b; b = &amp;a; </code></pre> <p>Variable b is simply pointing to the address location to a. Taking a deep dive into array concepts:</p> <pre><code>int a[5]; int *b = a; </code></pre> <p>Here we are just saying like <strong>Mr.*b</strong> point to the first location of group <strong>a</strong> i.e. <strong>a[0]</strong>.</p> <p>Now the power pointer in C is that from now on, here after:</p> <pre><code>*b means a[0] *(b+1) means a[1] *(b+2) means a[2] *(b+3) means a[3] *(b+4) means a[4] </code></pre> <p>This means you change in *(b+4), you're changing a[4]. </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. 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.
 

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