Find the size of a string pointed by a pointer

前端 未结 9 1050
一整个雨季
一整个雨季 2020-12-08 20:39
#include 

int main ()
{
    char *ptr = \"stackoverflow\"

}

Is there any way to find the length of stackoverflow pointed by ptr, a

9条回答
  •  情话喂你
    2020-12-08 21:04

    The strlen() function provided by string.h gives you how many "real characters" the string pointed by the argument contains. However, this length does not include the terminating null character '\0'; you have to consider it if you need the length to allocate memory.

    That 4 bytes is the size of a pointer to char on your platform.

提交回复
热议问题