这是源码
char target[80]="hello", *tar;
tar=⌖
printf("%s",tar); //printing hello
tar
获取 target[0]
的地址,然后打印整个字符数组。
最佳答案
当你说 %s 并指定字符串的起始内存(或任何中间)时,它会被打印直到遇到 '\0' 字符。
考虑
char *name = "Hello";
将在内部存储为 你好\0
因此,如果您需要单个字符,请使用 %c。
关于c - 为什么要打印完整的字符数组而不是第一个字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21085450/