We have been talking about this guy for so long and he finally came
And you will see him most of the time whenever you write a C code.
And you will see him most of the time whenever you write a C code.
So,
What printf() function do?
It basically prints everything within the double quotation.
for example:
printf("I am a programmer");
this prints:
I am a Programmer
In full code that will be-
#include <stdio.h>
int main()
{
printf("I am a Programmer");
return 0;
}Now, see another code
#include <stdio.h>
int main()
{
printf("I am a Programmer");
printf("I am a Programmer");
return 0;
}the output will be:
I am a ProgrammerI am a Programmer
The output is like this because we haven't use newline character to indicate the end of the line. So, the correction of the code will be:
printf("I am a Programmer\n");
printf("I am a Programmer");
that will do the desired output:
I am a Programmer
I am a Programmer
but if we insert a third line saying printf("I am a Programmer"); then it will show the same problem. So, I prefer to write
printf("I am a Programmer\n");
look carefully at the code, you will find newline characters and TAB characters within printf() and they are responsible for this cool output.
Now play with it
Write a Paragraph
printf("I am a Programmer\n");
but it depends upon the problem requirement what we want in the output
Now look at this code
#include <stdio.h>
int main()
{
printf("I am a Programmer\n");
printf("\tI am a Programmer\n");
printf("\t\tI am a Programmer\n");
return 0;
}
Output:
I am a Programmer
I am a Programmer
I am a programmer
look carefully at the code, you will find newline characters and TAB characters within printf() and they are responsible for this cool output.
Now play with it
Write a Paragraph
Design something cool
or
Send cool messages to buddies or your special buddies 😉
or
Send cool messages to buddies or your special buddies 😉
Happy Coding
See You in the next tutorial
Comments
Post a Comment