Passing a string literal as a function parameter defined as a pointer

前端 未结 6 945
南旧
南旧 2021-02-05 20:19

I am reading the chapter on arrays and pointers in Kernighan and Richie\'s The C Programming Language.

They give the example:

/* strlen:  return         


        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-05 20:39

    Note that:

    • A pointer is (basically) a value pointing to a memory address.
    • A static string like "hello, word" is stored somewhere in memory

    So, a pointer could as easily simply point to a static string as to any other (dynamical) structure that is stored in memory (like an array of characters). There is really no difference with the other provided examples.

提交回复
热议问题