current position:Home>Operation of strlen function

Operation of strlen function

2022-02-03 01:19:29 CSDN Q & A

char s[]="\n123\";
Why is the output of this program after execution 5,6 Well

Refer to the answer 1:

First, this is a string containing five valid characters
\n, 1, 2, 3, \
And a '\0' Terminator
strlen Don't count \0 So it is 5
sizeof Calculation \0 So it is 6

Refer to the answer 2:

Refer to the answer 3:

strlen(s), Get the number of valid characters
sizeof(s), Get the number of occupied space , Including... At the end of the string '\0',
therefore sizeof(s) Than strlen(s), many 1

Refer to the answer 4:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended