codescracker


c++

C++ Keywords



« Previous Tutorial Next Tutorial »


Keywords are the words that convey a special meaning to the language compiler. These are the reserved words for special purpose and must not be used as normal identifier names.

C++ Complete Keywords List

Following table lists the Complete C++ Keywords :

Keywords Newer Keywords
asm continue float new signed try using
auto default for operator sizeof typedef namespace
break delete friend private static union bal
case do goto protected struct unsigned static_cast
catch double if public switch virtual const_cast
char else inline register template void dynamic_cast
class enum int return this volatile true
const extern long short throw while false

Note : Identifiers containing a double underscore (_ _) are reserved for use by C++ implementations and standard libraries and should be avoided by users.

C++ Keywords Example

Following example shows the uses of some of the C++ keywords :

/* C++ Keywords Example */

#include<iostream.h>
#include<conio.h>
#include<dos.h>

void main()
{
	clrscr();
	
	/* This program uses the following
	   C++ keywords (most widely used) :
	   for, if, else, int */
	   
	int num, times, i;
	
	cout<<"Enter a number between 1...99 ";
	cin>>num;
	
	if(num>0 && num<100)
	{
		cout<<"What an honest employee!!";
	}
	else
	{
		cout<<"Bad employee!!";
	}
	
	cout<<"\nEnter number of seconds to blast the Bomb : ";
	cin>>times;
	
	for(i=times; i>0; i--)
	{
		cout<<i<<" ";
		sound(1000);
		delay(150);
		nosound();
	}
	
	cout<<"Fire!!!";
	
	getch();
}

When the above C++ program is compile and executed, it will produce the following output:

c++ keywords

Above program is just example of showing the uses of C++ keywords (if, for, else, int), So don't be confuse with the sound action, this is just a part of C++ Graphics.

Note - To perform the sound action on your own computer/laptop using TurboC++ compiler, you have to make following changes :

Let's look at one more example on C++ keywords, this C++ program uses the these C++ keywords: char, do, while, switch, break, and default

/* C++ Keywords Example2 */

/* This C++ program uses the
   following keywords :
   char, do, switch, while, break,
   default */

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>

void main()
{
	clrscr();

	char choice, name[15], rollno, marks;

	do
	{
		cout<<"\n1. Enter Your Name\n";
		cout<<"2. Enter Your Roll No.\n";
		cout<<"3. Enter Your Marks\n";
		cout<<"4. Exit\n";
		cout<<"Enter desired Option (1-4) : ";
		cin>>choice;
		switch(choice)
		{
			case '1' : cout<<"What is your Name ? ";
				cin>>name;
				cout<<"Your Name is "<<name;
				break;
			case '2' : cout<<"What is Your Roll Number ? ";
				cin>>rollno;
				cout<<"Your roll number is "<<rollno;
				break;
			case '3' : cout<<"Enter Marks obtained in the examination : ";
				cin>>marks;
				cout<<"You got "<<marks;
				break;
			case '4' : cout<<"press any key to exit...";
				getch();
				exit(0);
			default : cout<<"You entered out of 1...4";
				break;
		}
	}while(choice != 4);

	getch();
}

When the above C++ program is compile and executed, it will produce the following output:

keywords in c++ programming

Note - If you have any problem in understanding the concepts of the above programs, then just leave it, and go further, you will learn all the concepts in the separate chapters later.

More Examples

Here are some more C++ example programs listed, that you can go for:


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test