+ 1

Why the output contains inrrelevent characters ?

The output contains irrelevent characters if only 0 index of array is initialised .. If index from 0-3 is initialised here then there is no abitrary characters ! https://code.sololearn.com/cRMR2D3x9GkS/?ref=app

26th Feb 2021, 7:59 PM
Krishna Kumar
Krishna Kumar - avatar
2 Answers
+ 3
An array is allocated memory. C does not initialise its memory automatically. So what you see is left over data from the previous owner of that memory. Which is rubbish and a potential threat of bugs. Especially in C always initialse the variable's you are going to use,
26th Feb 2021, 8:11 PM
sneeze
sneeze - avatar
+ 1
Martin Taylor Since my char array has 6 characters and I've initialised only first character then why only 2 or 3 random characters are printed instead of all the remaining 5 ? And since I've not mentioned a null character in my char array why the printf() has stopped printing characters after those 2 or 3 garbage characters. ?
27th Feb 2021, 4:41 AM
Krishna Kumar
Krishna Kumar - avatar