#include<stdio.h>
#include<string.h>
static char* abc = "kj";

// What exactly does this function do?
void fn(char**s) {
	printf("arg: %p\n", s);
	printf("arg deref before: %p\n", *s);
	
	// This throws. *s is not a valid address.
	// printf("contents: ->%s<-\n", *s);
	
	*s = abc;
	printf("arg deref after assigning abc: %p\n", *s);
	
	// Now *s holds a valid address (that of "kj").
	printf("contents: ->%s<-\n", *s);
	
}

// Helper function to print a char pointer and the first bytes
// it points to
void printStr(const char *const caption, const char *const ptr)
{
	int i=0;
	printf("%s: ->%s<-, i.e. {", caption, ptr);
	for( i=0; i<sizeof(char *)-1; ++i)
	{
	    printf("0x%x,", ptr[i]);
	}
	printf( "0x%x ...}\n", ptr[sizeof(char *)-1] );
}

int main() {
   char str[256];
   
   printf("size of ptr: %zu\n", sizeof(void *));
   strcpy(str, "AAAAAAAA"); // 9 defined bytes
   printStr("str", str);
   printf("arr addr: %p\n", &str);
   printf("addr of abc: %p\n", abc);
   
   fn(&str);
   
   
   printStr("str after fn (a pointer value, only accidentally printable): ", str);
   printf("arr addr after fn: %p\n", &str);
   
   return 0;
}