我编写了以下代码,它使用指针从一个字符串复制到另一个字符串。
#include<stdio.h>
int main() {
char strA[80] = "A string to be used for demonstration purposes";
char strB[80];
char *ptrA;
char *ptrB;
ptrA = strA;
ptrB = strB;
puts(ptrA);
while(*ptrA != '\0') {
*ptrB++ = *ptrA++;
}
*ptrB = '\0';
puts(ptrB); // prints a new line.
return 0;
}
为什么puts(ptrB)
只打印一个换行符?但是puts(ptrA)
打印 的值strA
。