For_loop doubt | SoloLearn: Learn to code for FREE!

+1

For_loop doubt

https://code.sololearn.com/ctbxIKrtLzlF hi friends , here the expected output is eight nine even odd but with this code ....I am getting output as eightnine nine even odd how can i get ....expected output....?

6/15/2019 5:50:49 AM

malepu rakesh

1 Answer

New Answer

+3

In C, strings end in a '\0' (NUL) character. Because your declaration is x[...][5], the terminating NUL character of "eight" can not be stored, so printf does not know when eight ends. Because "eight" and "nine" are stored sequentially in memory, printf continues searching, until it finds nine's '\0'. To solve this bug, declare it as char x[...][6]