The purpose of the printf() function is to display a message to the user or to get the data required by the program from the user.
eg:
If you want to get his name from the user, printf("enter our name") is used. This method is used to ask the user.
syntax:
printf(" ");
Any message we give inside these double quotes will be displayed on the monitor.
Importantly, semicolon(;) should be given at the end. If semicolon(;) is not given, syntax error will occur in programming.
Escape Sequence:
They are very helpful in bringing us the expected output.
A backslash(\) followed by another character is an escape sequence.
\n-\n is new line.
Eg:
printf(“red\ngreen”);
output:
red
green
Instead of showing red green in a single row, they show it in a row.
\t-\t is tab(horizontal).
When using this you get 4 spaces between two words.
Eg:
printf(“red\tgreen”);
Output:
Red green
\'-\' are single quotes.
Single quotes are used to show the word and sentence inside.
Eg:
printf(“I Love\'Code\'”);
Output:
I Love 'Code'
And there are many escape sequences like this.