Before we use the printf and scanf function we must be know that :
=>C programming has several built functions to perform input and output tasks. Two commonly used functions for Input and Output are:
printf() and scanf()
The printf() function sends formatted output to the standard output (screen).
Now we take an example
Example 1:
#include int main() { printf("Hello C Programming"); return 0; }
Explanation of Above program
#include
The printf() function is declared in "stdio.h" header file and #include is a preprocessor directive to paste the code from the header file when necessary.
When the compiler encounters printf() function and doesn't find stdio.h header file, compiler shows error.
Note : if you are using turbo c editor the don't use this include statement but if you are using any c++ editor the its must be declare before the writing the main function.
printf("Hello C Programming");
The printf() is a library function to send formatted output to the screen. where " Hello c Programming " is our text (string constant ) which we want to display.
return 0;
This statement is the "Exit status" of the program. In simple terms, program ends.
Example 2: Integer Output
Explanation of Above program
In this program printf function passing two argument. in the inverted commas "Your Marks=" is the text (string constant ) print same on the screen. and 2nd one is marks (variable).
%d is format specifiers which tell to complier that the variable marks is integer variable and print at that place where the %d is place.
its means the above program display the result on the screen as
Your Marks are =500
Following are the some Format specifiers.
|
%d |
Integer |
|
%f |
Float |
|
%e |
Exponent |
|
%g |
General |
|
%c |
Character |
|
%s |
Siring |
|
%u |
Unsigned |
|
%1 |
Long |
|
%o |
Octal |
|
%x |
Hexa |
we cal also use [Escape Sequences] Back slash Character Constants
For example \n which control the cursor position . if we want to display the result on next line then we use \n before displaying the result.
printf(" Hello") ;
printf("\n C leraninghints.com");
The result of above tow statement is :
Hello
C leraninghints.com
but if we use :
printf(" Hello") ;
printf("C leraninghints.com");
The result of above tow statement is:
Hello C leraninghints.com
Declaring and Initializing Local Variable in C
Declaring and Initializing Global Variable in C Language
Printf Function In C Language
Sacnf Function In C Language
for Loop in C Language
While Loop in C Language
Do While Loop in C Language
Switch Case Statement IN C
IF -Else Statement IN C
Break Statement IN C /C++
User Define Function IN C /C++
Cout/Cin Function IN C /C++
Array IN C /C++
Two Dimensional Array IN C /C++
String In IN C /C++
Pointer In IN C /C++
Const and volatile keyword IN C /C++
Class and Object in C++
Function Over Loading in C++
Character Array In C++
Constructor in C++
Operator overloading in C++
Function Templates in C++
ATM Sample Project In Simple C Language
Find Area of Shape Using Function In C++