C programming language provides built-in functions to perform output operation. The output operations are used to display data on user screen (output screen) or printer or any file. The c programming language provides the following built-in output functions...
- printf()
- putchar()
- puts()
- fprintf()
printf() function
The printf() function is used to print string or data values or a combination of string and data values on the output screen. The printf() function is built-in function defined in a header file called "stdio.h".
The printf() function has the following syntax...
printf("message!");
Example
#include<stdio.h>
#include<conio.h>
void main(){
printf("Hello! Welcome to my tutorial!!");
getch();
}
#include<conio.h>
void main(){
printf("Hello! Welcome to my tutorial!!");
getch();
}
Output
The printf() function is also used to display data values. When we want to display data values we use format string of the data value to be displayed.
printf("format string",variableName);
Example
#include<stdio.h>
#include<conio.h>
void main(){
int i = 30;
float j = 2.5;
printf("%d \t %f",i, j);
getch();
}
#include<conio.h>
void main(){
int i = 30;
float j = 2.5;
printf("%d \t %f",i, j);
getch();
}
Output
To display the output in different lines or as we wish, we use some special characters called escape sequences.
Escape sequences are special characters with special functionality used
in printf() function to format the output according to the user
requirement.
putchar() function
Example
#include<stdio.h>
#include<conio.h>
void main(){
char ch = 'Z';
putchar(ch);
getch();
}
#include<conio.h>
void main(){
char ch = 'Z';
putchar(ch);
getch();
}
Output
puts() function
Example
#include<stdio.h>
#include<conio.h>
void main(){
char name[30];
printf("\nEnter your name: ");
gets(name);
puts(name);
getch();
}
#include<conio.h>
void main(){
char name[30];
printf("\nEnter your name: ");
gets(name);
puts(name);
getch();
}
Output
fprintf() function
No comments:
Post a Comment