Why printf ("% c", 1) returns a smiley instead of an encoded char for 1
This is my code.
#include <stdio.h> int x,y; int main( void ) { for ( x = 0; x < 10; x++, printf( "\n" ) ) for ( y = 0; y < 10; y++ ) printf( "%c", 1 ); return 0; } It returns emoticons. I searched everywhere for emoticon code or code for 1, but I could not find any links or any explanation why the char value for 1 returns the emoticon when the ascii code for 1 is SOH. I researched the answers to this question, but I did not find the answers explaining why this is happening.
The output depends on different terminals. For example, on my terminal, by default, OS X does not display any characters.
In your case, ☺ is inferred presumably due to some historical reasons . In short, this is because codepage 437, which maps byte 0x01 to U+263A , is an MS-DOS character set.