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
  • 349,597
  • 67
  • 533
  • 578
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
  • 205,898
  • 23
  • 218
  • 273