Register Now

Login

Lost Password

Enter your email to reset your password.

BY Author

The printf() function

The printf() is a standard output library (in built) function used to print output data to the console (display screen).
According to the format string & variable list, this function converts data into the string & then prints that string on console.

Syntax

 printf(“format string”,variable_list);

Example No. 1 printf() function to print integer value

 #include
 int main()
 {
     int i = 5;
     printf("%d",i);
     return 0;
 }

Output

 5

Example No. 2 printf() function to print string directly

 #include
 int main()
 {
     printf("Hello World");
     return 0;
 }

Output

 Hello World

Example No. 3 printf() function to print float value

 #include 
 int main() 
 { 
     float x = 6.33; 
     printf("%f",x); 
     return 0; 
 }

Output

 6.330000

Example No. 4 printf() function to print character value

 #include
 int main()
 {
     char ch = 'A';
     printf("%c",ch);
     return 0;
 }

Output

 A

Example No. 5 printf() function to print integer, float & character values

 #include
 int main()
 {
     int i = 10;
     float x = 7.34;
     char ch = 'W';
     printf("%d \n%f \n%c",i,x,ch);
     return 0;
 }

Output

 10
 7.340000
 W

 

Leave a reply