printf in C--pointer variable for %p %c %s
c, printf, string-formatting
Solution
`%s` will interpret the address of `msg` as the base addresss of a C string, which is a NULL terminated (`'\0'`) sequence of bytes, and therefore the printf with the `%s` will take the base address of `msg` and print the character equivalent of each byte starting from `msg` and proceeding until it does not encounter a NULL character.
Problem
``` void say(char msg[]) { // using pointer to print out the first char of string printf("%c\n", *msg); } void say(char msg[]) { // using pointer to print out the memory address of the first char of string printf("%p\n", msg); } void say(char msg[]) { // using pointer to print out the whole string printf("%s\n", msg); } ``` The first two make sense, but I don't quite understand how the third function works. All I know is that msg points to the memory address of the first character of the string. Thanks in advance.