Ads 468x60px

Saturday, 29 December 2012

Identifier, Keywords & Variables

2. Keywords
3. Variables

The name given to program elements often to variables. The rules of giving name are:

  1. Characters (a-z, A-Z) and numbers (0-9) and underscore( _ ) can only be used. 
  2. An identifier must start from a character or underscore we can not start the name with numbers. 
  3. As we know that C++ is a case sensitive language so case is distinguishable i.e. ID and id can be used as separate identifiers. 
  4. We can not use a keyword as an identifier. 
Legal Identifiers

Illegal Identifiers
this is your identifier

These are standard identifier that are predefined in C++.
Rules of Keywords:

  1. Keywords can be only used for their defined purpose. 
  2. Keywords can't be used as an identifier. 
  3. Keywords can't be used as a variable name. 

Some common keywords are: void, long, else, do, goto, char, int etc.
Variable is the name given to a specific memory location to store some values, the size is depends on the type of the variable which is declared by the programmer.

The syntax of declaring a variable is
data_type variable_name = value

Rules of declaring variable

  1. All variable must be declared before its use in the program. 
  2. All declaration of the same data type can be separated by comma (,) and the declaration is terminated by semi colon (;) 
int a,b,c;  
float x;
char z;
Share if you liked this Post using your favorite sharing service:

Subscribe Updates, Its FREE!


Post a Comment

Related Posts Plugin for WordPress, Blogger...