sheffield

Incrementing a Pointer

Dec 5th, 2021 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. const int MAX = 3;
  4.  
  5. int main () {
  6.  
  7.    int  var[] = {10, 100, 200};
  8.    int  i, *ptr;
  9.  
  10.    /* let us have array address in pointer */
  11.    ptr = var;
  12.    
  13.    for ( i = 0; i < MAX; i++) {
  14.  
  15.       printf("Address of var[%d] = %x\n", i, ptr );
  16.       printf("Value of var[%d] = %d\n", i, *ptr );
  17.  
  18.       /* move to the next location */
  19.       ptr++;
  20.    }
  21.    
  22.    return 0;
  23. }
Add Comment
Please, Sign In to add comment