Consider the following program.
Example-1
#include <stdio.h>
int main()
{
printf("Hello world");
printf("How are you?");
return 0;
}
There are two printf statements. You may
expect two lines of output. But the output is simply one line.
Output:
Hello worldHow are you?
Process returned 0 (0x0) execution time : 0.016 s
Press any key to continue.
To make the output on two different lines
you have to put ‘\n’ at the end of first printf statement.
Example-2
#include <stdio.h>
int main()
{
printf("Hello world\n");
printf("How are you?");
return 0;
}
Output:
Hello world
How are you?
Process returned 0 (0x0) execution time : 0.047 s
Press any key to continue.
‘\n’ is the type of escape
sequence.it is called as new line escape sequence.
There are other escape sequences
also.
‘\t’ is tab space escape sequence.
Example-3
#include <stdio.h>
int main()
{
printf("Hello world\t");
printf("How are you?");
return 0;
}
Output:
Hello world How are you?
Process returned 0 (0x0) execution time : 0.047 s
Press any key to continue.
Instead of new line certain no of spaces
are inserted at the output.
Like that two print a ‘\’ character
on the output you have to type ‘\\’ in the program.
Also ‘\”’ is used to printf double
quotes in the output:
And ‘\’’ is used to print single
quote in the output.
Thank you.
Contact: 91 9629329142
You tube channel: programming Digest.
No comments:
Post a Comment