the purpose of putchar function? How putchar is used within C program? Compare putchar with getchar function.

putchar() is a standard library function defined in stdio.h header file. It is used for printing one character on the screen at a time.

The syntax of this function is,

putchar(ch);

where, ch is a char type variable.

The following program shows how to use this function.




#include
main()
{
char ch = 'A';
putchar(ch);
}

Upon execution this program prints out A on screen.

getchar() is standard library function to get one character from keyboard. The getchar() function echo's the character on screen followed by enter key. The syntax of this function is

ch = getchar().

Both the functions are defined in stdio.h header file.

No comments:

Post a Comment