Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected result from printf

Tags:

c

printf

#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

like image 847
Sandeep Avatar asked Dec 03 '22 06:12

Sandeep


1 Answers

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.

like image 107
Platinum Azure Avatar answered Dec 23 '22 17:12

Platinum Azure