Change value of variable through pointer : Pointer Calculation « Pointer « C Tutorial






#include <stdio.h>

int main(void)
{
  long num1 = 0;
  long num2 = 0;
  long *pnum = NULL;

  pnum = &num1;                              
  *pnum = 2;                                 
  ++num2;                                    
  num2 += *pnum;                             

  pnum = &num2;                              
  ++*pnum;                                   

  printf ("\nnum1 = %ld  num2 = %ld  *pnum = %ld  *pnum + num2 = %ld\n",
                                      num1, num2, *pnum, *pnum + num2);
  return 0;
}
num1 = 2  num2 = 4  *pnum = 4  *pnum + num2 = 8








10.5.Pointer Calculation
10.5.1.Store the address of number in pointer
10.5.2.Change value of variable through pointer
10.5.3.When the pointer is incremented by an increment operator, it is always right incremented.
10.5.4.Pointer arrays