【发布时间】:2010-06-17 01:41:40
【问题描述】:
我什么时候需要在 C 中为 scanf() 插入/不插入 &?谢谢。
int main()
{
char s1[81], s2[81], s3[81];
scanf("%s%s%s", s1, s2, s3);
// If replace scanf() with the expression below, it works too.
// scanf("%s%s%s", &s1, &s2, &s3);
printf("\ns1 = %s\ns2 = %s\ns3 = %s", s1, s2, s3);
return 0;
}
//programming is fun
//
//s1 = programming
//s2 = is
//s3 = fun
【问题讨论】:
-
我建议阅读 K & R 的 C 编程语言。这实际上不是关于 scanf 的问题,而是关于 C 中内存访问如何工作的问题。