Getch () is a way to get a user inputted character.It can be used to hold program execution, but the ‘holding’ is simply a side-effect of its primary purpose which is to wait until the user enters a character.
Getch();
Example of getch()
#include<iostream.h>
#include<conio.h>
void main(){
char c;
clrscr();
c=getch();
cout<<"C=" <<c;
getch();
}
Output
press a output is c=a
#include<iostream.h>
#include<conio.h>
void main(){
char c;
clrscr();
cin>>c;
cout<<"C=" <<c;
getch();
}
Output
s -> enter
C=s
Getche()
Like getch() this is
also non-standard function present in coini.h. It reads a single character from
the keyword and display immediately on output screen without waiting for enter key.
Example of getche()
#include<iostream.h>
#include<conio.h>
void main(){
char c;
clrscr();
c=getche();
cout<<"\nC=" <<c;
getch();
}
Output
b
C=b
Getchar()
It read from
standard input. It is not display immediately on output screen waiting for
enter key.
Example of getchar()
#include<iostream.h>
#include<conio.h>
void main(){
char c;
clrscr();
c=getchar();
cout<<"C=" <<c;
getch();
}
Output
k -> enter
C=k
Enum
enum is a user defined data type in c.It is
mainly used to assign names to integral constants, the names make a program
easy to read and maintain.The keyword ‘enum’ is used to declare new enumeration
types in c and c++.
Enum
day;
Example of enum
#include<iostream.h>
#include<conio.h>
enum OS{
mac=11,solaris=22,linux,kali,ubuntu,andriod
};
void main(){
clrscr();
cout<<"Mac=" <<mac;
cout<<"\nSolaris=",solaris;
cout<<"\nLinux=" <<linux;
cout<<"\nKali=" <<kali;
cout<<"\nUbuntu=" <<ubuntu;
cout<<"\nAndriod=" <<andriod;
getch();
}
Output
Mac=11
Solaris=22
Linux=23
Kali=24
Ubuntu=25
Andriod=26
0 Comments