4
Keywords and Reserved Words : Keywords are predefined identifiers, that are used in the syntax and can be used as identifiers again. Reserved words are the words in a programming language which has a fixed meaning and cannot be redefined by the programmer. They cannot be used as identifers(variables, functions etc). All reserved words and keywords are in lowercase letters. But be aware that this terminology is not standard. For example, In some books it was mentioned that Reserved words are also called as Reserved Keywords and some authors will use keyword in the same sense that we have used Reserved word. Infact all keywords are subset of Reserve words. Keywords can be redefined while Reserved words cannot be redefined and used. For example : #include<iostream> using namespace std; int main() // here main is the keyword { int main; // it can be redefined For Reference : http://comsciguide.blogspot.com/

Keyword

Embed Size (px)

Citation preview

Page 1: Keyword

Keywords and Reserved Words :

Keywords are predefined identifiers, that are used in the syntax

and can be used as identifiers again.

Reserved words are the words in a programming language

which has a fixed meaning and cannot be redefined by the programmer.

They cannot be used as identifers(variables, functions etc).

• All reserved words and keywords are in lowercase letters.

• But be aware that this terminology is not standard. For example, In

some books it was mentioned that Reserved words are also called as

Reserved Keywords and some authors will use keyword in the same

sense that we have used Reserved word.

• Infact all keywords are subset of Reserve words.

• Keywords can be redefined while Reserved words cannot be

redefined and used.

For example :

#include<iostream>

using namespace std;

int main() // here main is the keyword

{

int main; // it can be redefined

For Reference : http://comsciguide.blogspot.com/

Page 2: Keyword

main = 1;

cout<< main;

return 0;

}

Here main is the keyword. So it can be redefined and used as an

identifier.

Output :

1

#include <iostream>

using namespace std;

int main()

{

int auto;

auto = 1;

cout<< auto;

return 0;

}

Here auto is an Reserved word. It cannot be redefined. So it

gives an error.

In general reserved words and keywords need not coincide, but

in most modern programming languages, keywords are a subset of

reserved words, as this makes parsing easier, since keywords cannot be

For Reference : http://comsciguide.blogspot.com/

Page 3: Keyword

confused with identifiers. In some languages, like C or Python, reserved

words and keywords coincide, while in other languages, like Java, all

keywords are reserved words, but some reserved words are not keywords –

these are "reserved for future use".

Here is a list of Reserved words and keywords.

C++ Rerserved words :

The reserved words of C++ may be conveniently placed into 3

groups. In the first group we put those that were also present in the C

programming language and have been carried over into C++. There are

32 of these, and here they are:

auto const double float int short struct unsigned

break continue else for long signed switch void

case default enum goto register sizeof typedef volatile

char do extern if return static union while

There are another 30 reserved words that were not in C, are

therefore new to C++, and here they are:

asm dynamic_cast namespace reinterpret_cast try

bool explicit

For Reference : http://comsciguide.blogspot.com/

Page 4: Keyword

export new static_cast typeid

catch false operator template using

class friend private this typename

const_cast inline public throw virtual

delete mutable protected true wchar_t

The following 11 C++ reserved words have been added to

provide more readable alternatives for some of the C++ operators, but

they are not essential when the standard ASCII character set is being used.

and bitand compl not_eq or_eq xor_eq

and_eq bitor not or xor

Predefined Identifiers :

Here is a very short list of some of the predefined identifiers :

cin endl INT_MIN iomanip main npos stdcout include INT_MAX iostream MAX_RAND NULL string

For Reference : http://comsciguide.blogspot.com/