+ 3
Why does it output two array?
#include <stdio.h> using namespace std; int main() { int i,j,l; char a[14]={'c','e','f','h','i','k','n','o','w','x'}; char s[4]={'f','b','l','a'}; puts(s); return 0; } It outputs " fblacefhiknowx", and I know my array s doesnt have '\0' at the end, but why array a is output? https://code.sololearn.com/cEGd33GC79s6/?ref=app
6 Respuestas
+ 3
solution of you problem.
change char s[4]
char s[5] or any number which is greater than 4.
ex char s[10]
Reason:
the puts method print the element till it find \0. so after printing 'fbla' it is printing any Garbage value if you remove thr char a[14] it will give you some other Garbage value.
on increasing the size from 4 to any number bigger than 4.
is add \0 to the 5 place
+ 3
K plz wait for a sec or two...
+ 2
Did you check the answer properly. I don't think that will be the output Since you are doing puts for only one array only that array will be printed.
+ 2
Yeah, I checked, but it printed two arrays. You can run this code.
https://code.sololearn.com/cEGd33GC79s6/?ref=app
+ 2
thx, bro 😄