When I run this code without \n the output is hello5 but with \n the output is hello6, can someone explain?
#include <stdio.h>
//Compiler version gcc 6.3.0
int main()
{
int c;
c = printf("hello\n");
printf("%d",c);
return 0;
}
When I run this code without \n the output is hello5 but with \n the output is hello6, can someone explain?
#include <stdio.h>
//Compiler version gcc 6.3.0
int main()
{
int c;
c = printf("hello\n");
printf("%d",c);
return 0;
}
The printf function returns the total number of characters printed.
When you print "hello\n", that's 6 characters, so c is 6. When you print "hello", that's 5 characters, so c is 5.