#include <stdio.h>
#include <cs50.h>
int main(void)
{
string y, x;
y = x = get_string();
x[2] = '\0';
printf("%s", x);
printf("%s", y);
}
如果输入是abcdef
。此代码的输出是 abab
。为什么不是 ababcdef
。
最佳答案
那是因为 y
和 x
指向 get_string
返回的同一个字符串。
Reads a line of text from standard input and returns it as a
string
(char *
), sans trailing newline character. [...]
关于c - 为什么 x[2] 也重新分配 y 值?我该如何解决这个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43466635/