What’s the difference between \n [newline] and \r [carriage return]?
In particular, are there any practical differences between
\n
and\r
? Are there places where one should be used instead of the other?
I would like to make a short experiment with the respective escape sequences of \n
for newline and \r
for carriage return to illustrate where the distinct difference between them is.
I know, that this question was asked as language-independent. Nonetheless, We need a language at least in order to fulfill the experiment. In my case, I`ve chosen C++, but the experiment shall generally be applicable in any programming language.
The program simply just iterates to print a sentence into the console, done by a for-loop iteration.
Newline program:
#include
int main[void]
{
for[int i = 0; i < 7; i++]
{
std::cout