Serial.print() VS Serial.println()

Hello there!

Can you please explain to me the difference between Serial.print() and Serial.println() if there even is one???
I'm currently very confused about the meaning of both of them.

Thanks a lot!

2 Likes

Println() advances to the next line after printing what you give it.
So Serial.print("abc"); Serial.print("def"); prints

abcdef

while Serial.println("abc"); Serial.println("def"); prints

abc
def
2 Likes

Serial.println adds a carriage return and line feed character to the end of what is being printed. Serial.print doesn't add any thing.

Hi Zoomkat,
What does it means by a carriage return and line feed character?
Thanks

It ends the line and moves on to the next line of the output.

BoyBrand:
Hi Zoomkat,
What does it means by a carriage return and line feed character?
Thanks

This is what it looks like in the source code:

size_t Print::println(void)
{
** size_t n = print('\r');**
** n += print('\n');**
** return n;**
}

1 Like

BoyBrand:
Hi Zoomkat,
What does it means by a carriage return and line feed character?
Thanks

The names are relics from the days when typewriters were common.

"carriage return" referred to moving the carriage carrying the paper back to the start of the line.
"linefeed" referred to moving the paper up one line ready to type the next one.

On a typewriter they were usually used in combination and done by moving a lever that pushed the carriage fully to the right and advanced the paper by one line at the same time.

The names were carried forward when computer printers first appeared and are also used in respect of computer monitors when outputting text.

This one difference. By Serial.println(), we pass next line.

BoyBrand:
Hi Zoomkat,
What does it means by a carriage return and line feed character?
Thanks

You're not really nice for westfw, are you? He gave you a perfect example already!

Please note that this thread is nearly three years old.

I did not notice indeed... ::slight_smile: