1) strlen() vs sizeof()
Output of above C Program is D) 5 8 .
Why 🤔 ?
Firstly you should know how strlen() function and sizeof() operator works.
Now let us understand how strlen() function works.
The strlen() function counts the characters till the terminating null character (excluding) i.e (‘\0’)
Now take a look at the given problem,
strlen() function searches for that NULL character and counts the number of memory address passed.
so , strlen() counts the chars upto str .
The working of sizeof() operator is pretty clear!
It returns actual amount of memory allocated for the operand passed to it.
What content present inside that block is none of sizeof() operator’s business 😎!
Hence, correct output is 5 8 !!
Click on Execute button to Run above code:
The above explanation is given by Akash Patil.
For more programming related questions and fun,
Follow us on Instagram.
Click here to view Guess The Output series 6.