tags:

views:

105

answers:

3
#include<stdio.h>
int main()
{
    printf("He %c llo",65);
}

Output: He A llo

#include<stdio.h>
int main()
{
    printf("He %c llo",13);
}

Output: llo. It doesnt print He.

I can understand that 65 is ascii value for A and hence A is printed in first case but why llo in second case.

Thanks

+6  A: 

Man ascii:

Oct   Dec   Hex   Char
015   13    0D    CR  '\r'

Character 13 is carriage return so it prints He then returns to the beginning of the line and prints the remining llo.

stefanB
Note: it returns to the beginning of current line not to the beginning of next line, to return to the beginning of next line you would use `\r\n` - carriage return, line feed.
stefanB
stefanB: Or just `\n` in the case of *NIX and OS X, or plain `\r` in MacOS before OS X.
Mikael S
`stdout` is open in text mode, so `\n` should work anywhere.
caf
+9  A: 

ASCII 13 is carriage return, which on some systems simply moves the cursor to the beginning of the line you were just on.

Further characters then wipe out the earlier text.

Platinum Azure
+3  A: 
Mark Rushakoff