printf() prints whole array

前端 未结 2 1835
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-08 01:27

Let\'s assume I have the following code in my C program:

#include 

void PrintSomeMessage( char *p );

int main(int argc, char *         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-08 02:02

    But still, the memory address for each letter in this address is different.

    Memory address is different but as its array of characters they are sequential. When you pass address of first element and use %s, printf will print all characters starting from given address until it finds '\0'.

提交回复
热议问题