New Lines
![]() |
How To Create New Lines In C? |
To the insert a new line, so you can use the \n
character:
Example
#include <stdio.h>
int main() {
printf("Hello World!\n");
printf("I am learning C.");
return 0;
}
OUTPUT:
Here You can also output multiple lines with a single
printf()
function. So, be aware that it will make the code harder to read:Example
#include <stdio.h>
int main() {
printf("Hello World!\nI am learning C.\nAnd it is awesome!");
return 0;
}
OUTPUT:
Tip: Here Two
\n
characters after each other will create a blank line:Example
#include <stdio.h>
int main() {
printf("Hello World!\n\n");
printf("I am learning C.");
return 0;
}
OUTPUT:
What is
\n
exactly?To the newline character (\n
) is called an escape sequence, and it is forces the cursor to change its position to the beginning of the next line on the screen. Its results in a new line.
To the examples of other valid escape sequences are:
Escape Sequence | Description |
|
\t | Creates a horizontal tab |
|
\\ | Inserts a backslash character (\) |
|
\" | Inserts a double quote character |
Post a Comment