Why does scanf() need & operator (address-of) in some cases, and not others?

后端 未结 5 1815
情深已故
情深已故 2020-11-28 13:29

Why do we need to put a & operator in scanf() for storing values in an integer array but not while storing a string in a char array?

         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-28 13:51

    Because characters arrays are already pointers.

    You can think of C arrays as pointers to a stack-allocated amount of RAM. You can even use pointer operations on them instead of array indexing. *a and a[0] both produce the same result (returning the first character in the array).

提交回复
热议问题