docs/c #427
Unanswered
docs/c
#427
Replies: 4 comments 1 reply
-
欢迎补充修正 |
Beta Was this translation helpful? Give feedback.
0 replies
-
"取消引用"这个说法感觉没有"取值"清晰,一提到引用难免想到C++的引用这一内容。而在C语言中似乎是没有引用这一概念的,我记得&是取地址操作,那么*操作最好是取值 |
Beta Was this translation helpful? Give feedback.
0 replies
-
字符串这里: printf("%s", greetings); |
Beta Was this translation helpful? Give feedback.
1 reply
-
谢谢你的解答,非常感谢 :)
…------------------ 原始邮件 ------------------
发件人: "jaywcjlove/reference" ***@***.***>;
发送时间: 2024年4月9日(星期二) 下午5:06
***@***.***>;
***@***.******@***.***>;
主题: Re: [jaywcjlove/reference] docs/c (Discussion #427)
在C语言中,字符串以 null 字符('\0')结尾。在你的例子中,greetings 数组定义为 {'H','e','l','l','\0'},这意味着字符串 "Hell" 后面有一个 null 字符作为字符串的结束标志。
当你使用 printf("%s", greetings); 来打印字符串时,printf 函数会从 greetings 数组开始逐个输出字符,直到遇到 null 字符为止,这样就会打印出 "Hell"。然而,你可能会观察到一个感叹号('!')出现在输出的末尾。这是因为 printf 函数在打印字符串后不会自动添加换行符,所以感叹号是在之前的输出行的最后一个字符。要解决这个问题,你可以在 printf 格式字符串中添加换行符,或者在输出后显式地添加换行符。
示例代码:
#include <stdio.h> int main() { char greetings[] = {'H','e','l','l','\0'}; printf("%s\n", greetings); // 添加换行符 // 或者 printf("%s", greetings); printf("\n"); // 显式地添加换行符 return 0; }
这样输出就不会出现感叹号了。
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
docs/c
http://localhost:1987/docs/c.html
Beta Was this translation helpful? Give feedback.
All reactions