Explain this to me please Given the short code sequence belo

Explain this to me please
Given the short code sequence below: int i; char str[20] = \"x\"; for (i = 0; i

Solution

Answer: iv. Length of string = 9

we declared str char array with the initial value of \"x\".

for loop, we are running from 0 to 3. So 4 times this loop will iterate.

Inside loop, we are concating \"ox\" with char array str.

At 1st iteration, str value is xox

At 2nd iteration, str value is xoxox

At 3rd iteration, str value is xoxoxox

At 4th iteration, str value is xoxoxoxox

So After loop terminates, str value is xoxoxoxox. So strlen(xoxoxoxox) will return 9.

Explain this to me please Given the short code sequence below: int i; char str[20] = \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site