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指向字符串第一个字符的内存地址.提前致谢.
%s
将解释msg
作为C字符串的基地址的地址,这是一个NULL terminate('\0'
)字节序列,因此带有的printf %s
将取基本地址msg
并打印从每个字节开始的字符等效字符,msg
直到它不会遇到NULL字符.
归档时间: |
|
查看次数: |
6186 次 |
最近记录: |