C - Getchar
![getchar](https://wikitechy.com/cdn/tutorials/c-programming/getchar.gif)
Learn C - C tutorial - Getchar - C examples - C programs
C - getchar() - Definition and Usage
- In C- Programming the getchar function is similar to the scanf statement, which will accept a character from the console file (console file is the output window where we can get the input values) or from a file, displays immediately while typing (after typing we need to press Enter key for proceeding).
![C Get Char C Get Char](https://wikitechy.com/cdn/tutorials/c-programming/c-getchar.png)
C Syntax
Datatype getchar(void);
Sample Coding - Get Char
#include<stdio.h>
#include<conio.h>
void main()
{
char x;
clrscr();
printf("Enter a character \n");
x=getchar();
printf("Given Character is %c \n",X);
getch();
}
C Code - Explanation
![code-explanation-type-casting code-explanation-type-casting](https://wikitechy.com/cdn/tutorials/c-programming/code-explanation-getchar.png)
- In this statement we declare the variable “X” as char data type.
- In this statement we are getting the char value which will be stored in the variable “x”.
- Here the printf statement is used for printing the value of the variable”x”.
Output :
![type-casting-sample-output type-casting-sample-output](https://wikitechy.com/cdn/tutorials/c-programming/getchar-sample-output.png)
- Here in this output we get the character “W” and the character will be displayed using the printf statement in the console window of C.