我想的是:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main(void) {
//test pointer to string
char s[50];
char *ptr=s;
printf("\nEnter string (s): ");
fgets(s, 50, stdin);
printf("S: %s\nPTR: %s\n", s, *ptr);
system("PAUSE");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
或者我应该使用*(s + i)和格式说明符%c的for循环?这是通过指针和简单的printf打印字符串的唯一可能方法吗?
更新:printf使用数组的第一个元素的地址进行操作,所以当我使用*ptr时,我实际上是使用第一个元素而不是它的地址.谢谢.