RicardasSim

pointer test c

Oct 24th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <inttypes.h>
  4.  
  5. int main (int argc, char **argv)
  6. {
  7.  
  8.     char pTestStr[] = "148";
  9.  
  10.     char *pStrPointer = pTestStr;
  11.    
  12.    
  13.     printf("Test01.  Value: %c   pTestStr: %s\n", *pStrPointer+1, pTestStr);
  14.     printf("Test02.  Value: %c   pTestStr: %s\n", pStrPointer[1], pTestStr);
  15.  
  16.     printf("Test03.  Value: %c   pTestStr: %s\n", *pStrPointer, pTestStr);
  17.    
  18.     printf("Test04.  Value: %c   pTestStr: %s\n", *pStrPointer++, pTestStr);
  19.     printf("Test05.  Value: %c   pTestStr: %s\n", *pStrPointer, pTestStr);
  20.  
  21.     printf("Test06.  Value: %c   pTestStr: %s\n", (*pStrPointer)++, pTestStr);
  22.     printf("Test07.  Value: %c   pTestStr: %s\n", *pStrPointer, pTestStr);
  23.    
  24.     printf("Test08.  Value: %c   pTestStr: %s\n", ++*pStrPointer, pTestStr);
  25.     printf("Test09.  Value: %c   pTestStr: %s\n", *pStrPointer, pTestStr);
  26.  
  27.     printf("Test10.  Value: %c   pTestStr: %s\n", *++pStrPointer, pTestStr);
  28.     printf("Test11.  Value: %c   pTestStr: %s\n\n", *pStrPointer, pTestStr);
  29.    
  30.     printf("TestAddr1.  Address: 0x%" PRIXPTR "\n", (uintptr_t) &pTestStr); //address of array
  31.     printf("TestAddr2.  Address: 0x%" PRIXPTR "\n\n" , (uintptr_t) &pTestStr[0]); //address of the first element of an array   
  32.    
  33.     /*
  34.     output:
  35.    
  36.     Test01.  Value: 2   pTestStr: 148
  37.     Test02.  Value: 4   pTestStr: 148
  38.     Test03.  Value: 1   pTestStr: 148
  39.     Test04.  Value: 1   pTestStr: 148
  40.     Test05.  Value: 4   pTestStr: 148
  41.     Test06.  Value: 4   pTestStr: 158
  42.     Test07.  Value: 5   pTestStr: 158
  43.     Test08.  Value: 6   pTestStr: 168
  44.     Test09.  Value: 6   pTestStr: 168
  45.     Test10.  Value: 8   pTestStr: 168
  46.     Test11.  Value: 8   pTestStr: 168
  47.  
  48.     TestAddr1.  Address: 0x7FFD21F683E4
  49.     TestAddr2.  Address: 0x7FFD21F683E4
  50.  
  51.     */
  52.    
  53.    
  54.     return 0;
  55. }
Add Comment
Please, Sign In to add comment