I knew that global int initalised array have default value 0, so I tried to see what default value a char array would have
char arr[10];
int main() {
for(int i=0;i<10;++i)
cout<<arr[i]<<endl;
return 0;
}
using this code I found output as <0x00> 10 times each in new line in the light text, i.e NUL, as expected by me, in console of sublime text (printing in terminal just gave 10 blank lines)
But then I tried to write the output to a file using freopen("output.txt", "w", stdout);
and to my surprise output changed to
000d 0a00 0d0a 000d 0a00 0d0a 000d 0a00
0d0a 000d 0a00 0d0a 000d 0a00 0d0a
also on removing endl output was
0000 0000 0000 0000 0000
further adding ' '
in place of endl gave 10 spaces only
I am unable to understand what's going on I expected zeros to be printed in all these cases, what's different in writing to a file to printing on terminal?
I looked up difference between NUL, NULL and 0 but still the output of these codes are not clear to me.
Can someone please help me to understand the reasoning? Thanks!