C multiple line printf



Break long Printf Statement Upto Multiple Lines in C :


Printf statement is used for displaying text,message or output of the program.So question is that “Can a long printf statement be broken up into multiple lines ?” Its answer is Yes we have 3 tricks by which you can break printf upto multiple lines
3 ways of Multiline

  1. Using “Backward Slash”.
  2. Using “Double Quotes”
  3. By Dividing Printf into Many Small Printf’s

Let us Discuss one by one –
1 . Using “Backward Slash”.

#include<stdio.h>
void main()
{
printf("C Programming is \
funny Language ");
}

Output :

C Programming is funny Language

Note :

  1. One printf can be broken into ‘n’ number of lines using “Backslash”
  2. No need to Close “Double Quotes” after first line.
  3. Opening Double Quote always on First Line while Closing Double Quote always on Last Line.

2 . Using “Double Quotes”

#include<stdio.h>
void main()
{
printf("C Programming is "
"funny Language ");
}

Output :

C Programming is funny Language

Note :

  1. Each Line needs Opening and Closing “Double Quote”.

3 . Break Long Printf in Small PRintf’s

#include<stdio.h>
void main()
{
printf("C Programming is ");
printf("funny Language ");
}

Output :

C Programming is funny Language