Why sizeof("xyz") is 4? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why sizeof("xyz") is 4?

whenever passing a string of length 'l' in the sizeof() operator it returns the length of string + 1. How is it working for strings?

22nd Mar 2017, 5:08 PM
Rax
Rax - avatar
3 Answers
+ 11
Because it is null terminated.
22nd Mar 2017, 5:18 PM
Karl T.
Karl T. - avatar
+ 5
Whenever we use double quotes it means Compiler treats it as a string. At the end of string there is always a null character i.e. \0 So including it,the result becomes 4
22nd Mar 2017, 5:20 PM
Abhishek Arora
Abhishek Arora - avatar
+ 1
Cool, So it was null character i am missing. thaknx @abhishek and @helioform
22nd Mar 2017, 6:15 PM
Rax
Rax - avatar