printf in C - %p%c%s的指针变量

use*_*937 3 c printf string-formatting

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);
}
Run Code Online (Sandbox Code Playgroud)

前两个有意义,但我不太明白第三个函数是如何工作的.我所知道的是,msg指向字符串第一个字符的内存地址.提前致谢.

pho*_*xis 5

%s将解释msg作为C字符串的基地址的地址,这是一个NULL terminate('\0')字节序列,因此带有的printf %s将取基本地址msg并打印从每个字节开始的字符等效字符,msg直到它不会遇到NULL字符.