C – Unformatted Output Function

Preview
You must first complete Read values in C- scanf() function before viewing this Lesson

C – Unformatted Output Function

There are  various output functions provided by C Language. These functions are used to display the value of a variable during the execution of program. Various unformatted output functions provided by C Language are as follows:

 1. putchar()

It stands for put character. It is used to display value of a character variable or character constant on the screen.

While using this function, we need to take character variable or character constant as an argument to this function whose value we want to display on screen.

The header file required for this function is <stdio.h>.

Syntax:

putchar(charvariable);

charvariable refers to the character variable or character constant whose value we want to display using putchar() function.

Program to display value of a character type variable using putchar()

Output

#include<stdio.h>
#include<conio.h>
int main()
{
char n;
printf(“\nEnter any character=”);
n=getchar();
printf(“\ncharacter=”);
putchar(n);
getch();
return (0);
}
Enter any character=H
character=H

2. putch()

It stands for put character. It is used to display value of a character variable or character constant on the screen.

While using this function, we need to take character variable or character constant as an argument to this function whose value we want to display on screen.

The header file required for this function is <conio.h>.

Syntax:           

putch(charvariable);

charvariable refers to the character variable or character constant whose value we want to display using putch() function.

Program to display value of a character type variable using putch()

Output

#include<stdio.h>
#include<conio.h>
int main()
{
char n;
printf(“\nEnter any character=”);
n=getchar();
printf(“\ncharacter=”);
putch(n);
getch();
return (0);
}
Enter any character=H
character=H

3. puts()

It stands for put string. It is used to display the value of a string variable or string constant on the screen.

When we use puts() function to display value of a string variable or string constant, it will automatically insert a new line character at the end of string variable or string constant.

The header file required for this function is <stdio.h>.

Syntax:

puts(str);

str referes to the string variable or string constant whose value we want to display using puts() function.

Program to display value of a character type variable using putchar()

Output

#include<stdio.h>
#include<conio.h>
int main()
{
char n;
char name[20];
clrscr();
printf(“\nEnter your name=”);
gets(name);
puts(“\nName=”);
puts(name);
getch();
return (0);
}
Enter your name=lovejot
Name= lovejot

Best Books of C

Best Books of C

Lesson tags: putch function of c, putchar function of c, puts function of c
Back to: C Programming Language