C New Lines

C Tutorial

1. Using \n for C New Lines

In C New Lines character \n is used to move the cursor to the next line when printing output.

Example:


 

Output:

Hello World
Welcome to C Programming

Here, \n after "Hello World" moves the cursor to the next line.


2. New Lines in the Middle of Text

You can also add \n anywhere in the string:


Output:

Line1
Line2
Line3

3. Using Multiple New Lines

  • You can use \n multiple times to create blank lines:


Output:

Hello

World

Notice the blank line between “Hello” and “World”.


4. Using \n vs puts()

  • puts() automatically adds a newline at the end, unlike printf().


 

Output:

Hello
World

No need for \n with puts().


5. Tips for New Lines

  1. Use \n in printf() for formatting output.

  2. Use multiple \n for spacing or blank lines.

  3. Use puts() for simple strings that require a newline automatically.

You may also like...