为什么不scanf函数需要字符串的符号和printf中也能正常工作(C语言)?
我学习关于C字符串了。
I am learning about strings in C now.
如何来使用scanf函数得到一个字符串,你可以做
How come to use scanf to get a string you can do
scanf("%s",str1);
和printf的,你可以做
and for printf you can do
printf("The string is %s\n", str1);
我明白,scanf函数这是因为字符串就是一个字符数组是一个指针,但对于printf的,是什么让你可以把变量名,就像你会为一个整数或浮点数?
I understand that for scanf it is because the string is just a character array which is a pointer, but for printf, how is it that you can just put the variable name just like you would for an int or float?
scanf函数
需要变量的地址读入和字符串缓冲区已经重新presented的地址(指针指向内存中的位置,或者分解成一个指针数组)。
scanf
needs the address of the variable to read into, and string buffers are already represented as addresses (pointer to a location in memory, or an array that decomposes into a pointer).
的printf
不相同,治疗%S
作为指针到字符串。
printf
does the same, treating %s
as a pointer-to-string.