sheffield

Pointer comparisons

Dec 5th, 2021
915
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 address of the first element in pointer */
  11.    ptr = var;
  12.    i = 0;
  13.    
  14.    while ( ptr <= &var[MAX - 1] ) {
  15.  
  16.       printf("Address of var[%d] = %x\n", i, ptr );
  17.       printf("Value of var[%d] = %d\n", i, *ptr );
  18.  
  19.       /* point to the previous location */
  20.       ptr++;
  21.       i++;
  22.    }
  23.    
  24.    return 0;
  25. }
RAW Paste Data