Why does this code work? I would expect that I would need to dereference ptr, printf(\"%s\\n\", *ptr); before I could print it out, but I get a
ptr
printf(\"%s\\n\", *ptr);
The format specifier %s tells printf to expect a pointer to a null-terminated char array. Which is what name and ptr are.
%s
printf
name
*name and *ptr are not. If you dereference them, you'll get back a single char, which is basically lying to printf - resulting in undefined behavior.
*name
*ptr
char