Getting wrong string length

前端 未结 3 1511
心在旅途
心在旅途 2021-01-26 18:00

I am trying to get the length of a string but i am getting the wrong value, it is saying that it is only 4 characters long. Why is this? am i using sizeof() correc

3条回答
  •  失恋的感觉
    2021-01-26 18:19

    You have declared s as a pointer. When applied to a pointer, sizeof() returns the size of the pointer, not the size of the element pointed to. On your system, the size of a pointer to char happens to be four bytes. So you will see 4 as your output.

提交回复
热议问题