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.
%swill interpret the address ofmsgas the base addresss of a C string, which is a NULL terminated ('\0') sequence of bytes, and therefore the printf with the%swill take the base address ofmsgand print the character equivalent of each byte starting frommsgand proceeding until it does not encounter a NULL character.