×

注意!页面内容来自https://www.scoolio.academy/course/c/new-line,本站不储存任何内容,为了更好的阅读体验进行在线解析,若有广告出现,请及时反馈。若您觉得侵犯了您的利益,请通知我们进行删除,然后访问 原网页

New Lines


New Lines

To insert a new lineyou can use the \n character:

Example

#include <stdio.h>

int main() {
  printf("Hello World!\n");
  printf("I am learning C.");
  return 0;
}

You can also output multiple lines with a single printf() function. Howeverthis could 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;
}

Tip: 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;
}

What is \n exactly?

The newline character (\n) is called an escape sequenceand 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
\t Creates a horizontal tab
\\ Inserts a backslash character (\)
\" Inserts a double quote character