C New Lines
1. Using \n for New Line
In C, the newline character \n is used to move the cursor to the next line when printing output.
Example:
Output:
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:
3. Using Multiple New Lines
-
You can use
\nmultiple times to create blank lines:
Output:
Notice the blank line between “Hello” and “World”.
4. Using \n vs puts()
-
puts()automatically adds a newline at the end, unlikeprintf().
Output:
No need for \n with puts().
5. Tips for New Lines
-
Use
\ninprintf()for formatting output. -
Use multiple
\nfor spacing or blank lines. -
Use
puts()for simple strings that require a newline automatically.
