fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct {
  5. char * name;
  6. } Player;
  7.  
  8. int main(void) {
  9. char * name;
  10. char * pname;
  11. Player * player;
  12.  
  13. name = "FIRST LAST";
  14.  
  15. // initialize player
  16. player = (Player *)malloc(sizeof(Player));
  17. player->name = name;
  18.  
  19. pname = player->name;
  20.  
  21. // print information about the variables
  22. printf("Printing Initial Variable Information:\n");
  23. printf("--------------------------------------\n");
  24. printf("Variable: name\n");
  25. printf("Location: `%p'\n", &name);
  26. printf(" Value: `%p'\n", *name);
  27. printf("Dref Val: `%s'\n", name);
  28. printf("\n");
  29.  
  30. printf("Variable: pname\n");
  31. printf("Location: `%p'\n", &pname);
  32. printf(" Value: `%p'\n", *pname);
  33. printf("Dref Val: `%s'\n", pname);
  34. printf("\n");
  35.  
  36. printf("Variable: player->name\n");
  37. printf("Location: `%p'\n", &(player->name));
  38. printf(" Value: `%p'\n", *(player->name));
  39. printf("Dref Val: `%s'\n", player->name);
  40. printf("\n");
  41.  
  42. // see what *(pname++) is doing
  43. printf("Checking what *(pname++) does:\n");
  44. printf("------------------------------\n");
  45. printf("Variable: pname\n");
  46. printf("Location: `%p'\n", &pname);
  47. printf(" Value: `%p'\n", *pname);
  48. printf("Dref Val: `%s'\n", pname);
  49. printf("\n");
  50.  
  51. *(pname++);
  52.  
  53. printf("Variable: pname\n");
  54. printf("Location: `%p'\n", &pname);
  55. printf(" Value: `%p'\n", *pname);
  56. printf("Dref Val: `%s'\n", pname);
  57. printf("\n");
  58.  
  59. // see what *(player->name++) is doing
  60. printf("Checking what *(player->name++) does:\n");
  61. printf("-------------------------------------\n");
  62. printf("Variable: player->name\n");
  63. printf("Location: `%p'\n", &(player->name));
  64. printf(" Value: `%p'\n", *(player->name));
  65. printf("Dref Val: `%s'\n", player->name);
  66. printf("\n");
  67.  
  68. *(player->name++);
  69.  
  70. printf("Variable: player->name\n");
  71. printf("Location: `%p'\n", &(player->name));
  72. printf(" Value: `%p'\n", *(player->name));
  73. printf("Dref Val: `%s'\n", player->name);
  74. printf("\n");
  75.  
  76. // see results
  77. printf("Printing Resulting Variable Information:\n");
  78. printf("----------------------------------------\n");
  79. printf("Variable: pname\n");
  80. printf("Location: `%p'\n", &pname);
  81. printf(" Value: `%p'\n", *pname);
  82. printf("Dref Val: `%s'\n", pname);
  83. printf("\n");
  84.  
  85. printf("Variable: player->name\n");
  86. printf("Location: `%p'\n", &(player->name));
  87. printf(" Value: `%p'\n", *(player->name));
  88. printf("Dref Val: `%s'\n", player->name);
  89. printf("\n");
  90.  
  91. return 0;
  92. }
  93.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Printing Initial Variable Information:
--------------------------------------
Variable: name
Location: `0x7ffebcaae830'
   Value: `0x46'
Dref Val: `FIRST LAST'

Variable: pname
Location: `0x7ffebcaae838'
   Value: `0x46'
Dref Val: `FIRST LAST'

Variable: player->name
Location: `0x2b889fcb3010'
   Value: `0x46'
Dref Val: `FIRST LAST'

Checking what *(pname++) does:
------------------------------
Variable: pname
Location: `0x7ffebcaae838'
   Value: `0x46'
Dref Val: `FIRST LAST'

Variable: pname
Location: `0x7ffebcaae838'
   Value: `0x49'
Dref Val: `IRST LAST'

Checking what *(player->name++) does:
-------------------------------------
Variable: player->name
Location: `0x2b889fcb3010'
   Value: `0x46'
Dref Val: `FIRST LAST'

Variable: player->name
Location: `0x2b889fcb3010'
   Value: `0x49'
Dref Val: `IRST LAST'

Printing Resulting Variable Information:
----------------------------------------
Variable: pname
Location: `0x7ffebcaae838'
   Value: `0x49'
Dref Val: `IRST LAST'

Variable: player->name
Location: `0x2b889fcb3010'
   Value: `0x49'
Dref Val: `IRST LAST'