Sei sulla pagina 1di 3

C programming code for getch

/* getch in c example */
#include<stdio.h>
#include<conio.h>
main()
{
printf("Waiting for a character to be pressed from the keyboard to
exit.\n");
getch();
return 0;
}

When you will run this program, the program will exit only when you press a
character, note that we are talking about a character so try pressing numlock,
shift key etc (program will not exit if you press these keys) as these are not
characters. Also try the above program by removing getch(), in this case
program will exit without waiting for a character being pressed from keyboard.

C programming code for getch


/* getch in c example */
#include<stdio.h>
#include<conio.h>
main()
{
printf("Waiting for a character to be pressed from the keyboard to
exit.\n");
getch();
return 0;
}

When you will run this program, the program will exit only when you press a
character, note that we are talking about a character so try pressing numlock,
shift key etc (program will not exit if you press these keys) as these are not
characters. Also try the above program by removing getch(), in this case
program will exit without waiting for a character being pressed from keyboard.

Potrebbero piacerti anche