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;
}
John Kugelman
  • 330,190
  • 66
  • 504
  • 555
overkill
  • 11
  • 2

1 Answers1

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.

dbush
  • 186,650
  • 20
  • 189
  • 240