Getting wrong string length
问题 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() correctly? #include <stdio.h> int main(void) { char *s; int len; s = "hello world"; len = sizeof(s); printf("%d\n", len); } 回答1: The sizeof operator is returning the size of the pointer. If you want the length of a string, use the strlen function. Even if you had an array (e.g. char s[] = "hello world" ) the sizeof operator would return