Why doesn’t scanf need &?
时间: 2024-05-27 17:11:22 浏览: 14
a reference operator for character arrays in C?
In C, character arrays are already passed by reference, which means that when you pass a character array to a function, you are actually passing a pointer to the first element of the array. This is why scanf() does not need a reference operator (&) when reading input into a character array.
For example, when you declare a character array `char str[50];`, `str` is already a pointer to the first element of the array. So when you pass `str` as an argument to scanf(), you are passing a pointer to the first element of the array, which is the correct way to pass a character array.
Thus, you do not need to use the reference operator (&) when passing a character array to scanf() because it is already passed by reference.