Identifiers and Keywords in C++ Programming

As we know every word in any computer language are either an identifiers or a keywords. But in C++ we have some rules to declare an identifiers. But in case of keywords, we don't need to do any thing because keywords are already reserved and defined in compiler like struct, break, continue, int, float etc. We only need to declare identifier when going to write any C++ program. For example

let's have a line of code below:

int x=10;  Here, 
int is a keyword which is already reserved for integer.
x is a variable which is further an identifier in C++.
10  is a constant value which is stored in x.

Now the question is how to name any identifier in C++. Identifiers are basically names given to program elements such as variables, arrays and functions. They are formed by using a sequence of letters ( uppercase and lowercase), numerals and underscore. So to name any identifier we have some rules which are discussed below:

1. We use only Capital (A-Z), small ( a-z), Digits (0-9) only.
2. In special character only underscore ( _ ) are allowed.
3. No space is allowed in between two characters or words.
4. Identifiers can't start with a digit. We can only use digit in between.
5. Identifiers can't be a reserved keyword of C++ language.
6. Identifiers can be of any reasonable length may be it should be of 31 characters.
7. It should be start with letter ( Uppercase or lowercase) or an underscore.
8. No two successive underscore are allowed.

Lets take an example for understanding identifiers rules:

Right Identifiers: First, Hello1, Hello_world, H12, H_12, _Hello etc.

Wrong Identifiers: 0hello, hello#123, hello world, $1abs, 12abc etc.

Keywords in C++ language are given below in table: All keywords are basically a sequence of characters that have a fixed meaning in C++ language. 

auto
break
char
int
continue
default
int
double
short
if
else
for
goto
enum
long
typedef
return
unsigned
sizeof
static
extern
struct
switch
union
void
register
do
while

We are only mention only few in this section. for more detail on this please go to www.google.com.



Thanks 
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: