The printf() Function
At first, we write a program :
#include<stdio.h> //header file void main() { printf(“It is C programming.”); //printf() function } ---------------------------------------------------------------- Output: It is C programming. |
printf() is a predefined standard C function for printing output. Predefined means that it is a function that has already been written and compiled and linked together with our program at the time of linking.
Actually it is use for showing something in the screen. printf() function is defined in the header file stdio.h (we discuss later more ). The printf() function causes everything between the staring and the ending quotation marks to be printed out.
When we show anything in the screen like a string, it must be written in the double quotation (“”) in the printf() function.
To better understand, Look at our program,
we write the statement,
printf(“It is C programming.”);
It is C programming. - this sentence is written in the double quotation in the printf() function. And we see the screen is: It is C programming.
Look at another thing, at first we include a header file in our program at first, because the printf() function is defined in this header file. If we do not include this header file, compiler can not link.
The printf() function ends with a semicolon. (Every statement of C should end with a semicolon (;) mark.)
We must note one important point, C does make a distinction between uppercase and lowercase letters. For example, printf and PRINTF are not the same. In C, everything is written in lowercase letters. Uppercase letters are used for symbolic names representing constants.
We may also use uppercase letters in output like : IT IS C PROGRAMMING.
Now we print two or more sentence in different line. what we do now?
In this case, we use some backslash character (/). Suppose, we need the following output:
It is C programming Language
Editing by Shojib.
now follow the statement :
printf(“It is C programming Language”);
printf(“Editing by Shojib.”);
when we write the statement like this, the output is following :
It is C programming LanguageEditing by Shojib.
Now follow this statement :
printf(“It is C programming Language\n”);
printf(“Editing by Shojib.”);
Now we get the output :
It is C programming Language
Editing by Shojib.
Now look at the first statement, we use the “\n” backslash character. It is generate the new line.
Another program of using backslash character in printf() function :
#include<stdio.h> void main() { printf(“That\tis\tShojib’s\torg.”); } --------------------------------------------------------------------------------- Output: That is Shojib’s org. |
Written by “Shojib”
No comments:
Post a Comment