#include <stdio.h>
int main()
{
char *name = "Bob";
printf("Name VAL: %p\n", name); //Value of name
printf("Name PTR: %p\n", &name); //Address of ptr itself
printf("Name VAL: %s\n\n", name);
char **p_name = &name;
printf("P_Name VAL: %p\n", p_name); //Address of name ptr
printf("P_Name PTR: %p\n", &p_name); //Address of ptr itself
printf("P_Name PTR PTR: %p\n", *p_name); //Derefences to string literal address "Bob"
printf("P_Name PTR: %s\n\n", *p_name);
printf("Changed the name pointer to point to John\n");
name = "John"; //Name ptr now points to new string literal
printf("P_Name PTR PTR: %p\n", *p_name); //This now derefences to string literal address "John" as p_name points to ptr name
printf("Name via Pointer: %s\n\n", *p_name);
void *pa = p_name; //Void pointer. Point to value of p_name. Points to address of name ptr
printf("PA VAL: %p\n", pa); //Address of name ptr
printf("PA PTR: %p\n\n", &pa); //Address of void ptr itself
//Test deferences pa before passing to test. Test points to the string literal John memory address
char *test = *((char**)pa); //CAST BEFORE DEREFERENCING
printf("TEST PTR: %p\n", test); //Address of John.
printf("TEST PTR: %s\n\n", test);
//Test2 points to the memory address of name ptr
char **test2 = (char**)pa; //CAST BEFORE DEREFERENCING
printf("TEST2 PTR PTR: %p\n", test2); //Address of name ptr
printf("TEST2 PTR PTR: %s\n\n", *test2); //Dereferences to print string literal name is pointing at
printf("Changed the name pointer to point to Charles\n");
name = "Charles"; //Name ptr now points to new string literal
//Test deferences pa before passing to test. Test points to the string literal John memory address. No Change
printf("TEST PTR: %p\n", test); //Address of John.
printf("TEST PTR: %s\n\n", test);
//Test2 points to the memory address of name ptr
printf("TEST2 PTR PTR: %p\n", test2); //Address of name ptr
printf("TEST2 PTR PTR: %s\n\n", *test2); //Dereferences to print string literal name is pointing at. Changes to Charles
return 0;
}