current position:Home>Why is the answer 3?

Why is the answer 3?

2022-01-26 23:38:17 CSDN Q & A

solve , Why? The answer is 3? It's hard to understand

#include<stdio.h>#include<string.h>int main(){    printf("%d", strlen("s\n\016\0end"));    return 0;}



Refer to the answer 1:

\0 Is the end of a string
\016 Represents an octal number
So the string length is 3 Namely
s \n \016




Refer to the answer 2:



Refer to the answer 3:

because strlen encounter \0 Think of the end of the string




Refer to the answer 4:



Refer to the answer 5:

1、\0 Is the terminator .
2、strlen In fact, the calculated string is “s\n\0”




Refer to the answer 6:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262338155498.html

Random recommended