getchar c
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
c = getchar();
printf("You entered: ");
putchar(c);
return 0;
}
Explanation:
#include <stdio.h>
: Includes the standard input-output library for basic input and output operations.int main() { }
: The main function where the program execution starts.char c;
: Declares a variablec
of type char to store a single character.printf("Enter a character: ");
: Displays a message prompting the user to enter a character.c = getchar();
: Usesgetchar()
to read a single character from the standard input (keyboard) and assigns it to the variablec
.printf("You entered: ");
: Displays a message indicating what the user entered.putchar(c);
: Outputs the character stored in the variablec
to the standard output (console).return 0;
: Indicates successful completion of themain()
function and the program terminates with a status code of 0.