C OUTPUT AND NEW LINE | C PROGRAMMING 3
-
by anonymous
- 22
C Output (Print Text)
Output (Print Text)
To output values or print text in C, you can use the printf() function:
You can use as many printf() functions as you want. However, note that it does not insert a new line at the end of the output:
Example
int main() {
printf(“Hello World!”);
printf(“I am learning C.”);
return 0;
}
New Lines
To insert a new line, you can use the n character:
Example
int main() {
printf(“Hello World!n“);
printf(“I am learning C.”);
return 0;
}
You can also output multiple lines with a single printf() function. However, this could make the code harder to read:
Example
int main() {
printf(“Hello World!nI am learning C.nAnd it is awesome!”);
return 0;
}
Tip: Two n characters after each other will create a blank line;
Example
int main() {
printf(“Hello World!nn“);
printf(“I am learning C.”);
return 0;
}
What is n exactly?
The newline character (n) is called an escape sequence, and it forces the cursor to change its position to the beginning of the next line on the screen. This results in a new line.
Examples of other valid escape sequences are:
| Escape Sequence | Description | Try it |
|---|---|---|
| t | Creates a horizontal tab | Try it |
| \ | Inserts a backslash character () | Try it |
| “ | Inserts a double quote character | Try it |
C Output (Print Text) What is C Output and New Line? In the C programming language, “output” means to display information using functions such as print() or puts(). “Newline” in C refers to a sequence of lines marking the end of a line of text, represented by a “n” escape sequence. This…
C Output (Print Text) What is C Output and New Line? In the C programming language, “output” means to display information using functions such as print() or puts(). “Newline” in C refers to a sequence of lines marking the end of a line of text, represented by a “n” escape sequence. This…
