Notes
Notes and insights I found from playing around with \b, \r and \n for a small timer I was trying to build by myself (without AI help, unless searching syntax counts)
- Compile: Translate source code (the code written in the programming language) to machine code (0’s and 1’s aka binary aka the only language a computer actually understands)
Runtime: From the point we open a program to the point of it closing / doing everything it’s suppossed to do
\n means move the cursor to the next line. \r is move the cursor to the very first space of the current line. \b is move the cursor back by one space. NONE of it ever actually deletes, pulls or moves the text written on the screen. Once it’s there it is TOTALLY there. If we write a code like:
#include <stdio.h>
int main (void)
{
printf ("Hello Alexa\b\n");
}
The result is something like this:
Hello Alexa
The program prints out Hello, Alexa; then the cursor sits on top of “a” (\b means go back a space) but when you give the command \n it doesn’t move the “a” to the next line, only the cursor goes to next line. It CAN NOT drag a with it to the new line. The printed lines are kinda stuck on the screen. Same happens if we type \r. It doesn’t erase ANYTHING. It moves the cursor to “H” and when \n comes it just moves the CURSOR to the next line, “H” stays in the same place.
The only way we can give an illusion of erasure is if we do something called “Overwrite it”. For example:
#include <stdio.h>
int main (void)
{
printf ("Hello World\r");
printf ("B");
}
The result will be:
Bello World // The cursor moves to "H" and then overwrites it aka write a "B" over the H
// The computer has no more memory of the "H" there on the screen. It is deleted.
If we do the same with \b instead of \r then we’ll see the result “Hello WorlB”.
However the compiler can read the spaces between the words you wanna type and the backslash commands. For example if you type:
#include <stdio.h>
int main (void)
{
printf ("Hello World \b");
printf ("B");
}
The result will be:
Hello WorldB
Because first we
- print out Hello World (with a space).
- when there is a \b the cursor comes right beside the letter “d”
- it prints the letter “B”
Compiler can even read the spaces between two backslash commands for example if you type \r space \n, then the compiler will act accordingly. Even your spaces matter when using these.
Top comments (0)