What is getch() in C
×


What is getch() in C

29

getch is a function in C, primarily used for console input without displaying the entered characters on the screen.

It's part of the conio.h header, commonly used in older versions of C and C++ for console-based applications.

Syntax of getch() in C:

int getch(void);

Parameters:

void: getch doesn't accept any parameters.

Return Value:

int: Returns the ASCII value of the key pressed by the user.

Examples:

Reading a Single Character and Displaying its ASCII Value:

// Program for getch() function in C
#include
#include

int main() {
    char ch;
    
    printf("Press any key: ");
    
    ch = getch();
    
    printf("\nASCII value of pressed key is %d\n", ch);
    
    return 0;
}
	

Output:

Press any key: A
ASCII value of pressed key is: 65



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments