Saturday 5 October 2013

Identifiers in C++

In this post of shapes in C, we are going to discuss sixth C tutorial for beginners in which we are going to discuss about identifiers in C++.

Identifiers are the names of things that appear in programs such as variables, constants and functions. There are some rules for identifiers in C++ that should be followed otherwise; the compiler would give the syntax error.

C++ identifiers:

A C++ identifier consists of letters, digits and the underscore character (_).

Rules:

  • The identifier should begin with a letter or underscore.
  • It should not start with a digit.
  • There should be no spaces between an identifier
  • No other symbols are allowed to write an identifier other than digits, letters and underscore.

Example of illegal identifiers:

  • My Book                             There is a space between My and book
  • 1stbook                               The identifier is starting with a digit
  • One+two                             The symbol ‘+’ can’t be used
  • Party!                                  The symbol ‘!’ can’t be used

Example of legal identifiers:

  • Book1                Here the digit is not used in the start
  • _size                  The identifier is started with underscore
  • Mybook              The identifier is started with an alphabet
  • Your_book     The identifier has two words which are separated by underscore

Types:

There are two types of identifiers:
  1. Predefined
  2. User defined

Example:

cout and cin is a predefined identifier whereas  num and word is a user defined identifier.

Note: In C++, identifiers can be of any length.

Caution: Identifiers are case sensitive. Uppercase and lowercase letters are considered different. So the identifier UPPER is not the same as the identifier upper.

Final Words:

In this c tutorial for beginners of shapes in c, you have learnt the meaning, use and rules of identifiers. In this c tutorial for beginner, we discussed the topic of C++ identifiers types, cautions, important notes and illegal and legal identifiers with examples and its explanation in detail.This c programming tutorial has been designed keeping in mind the beginners in C++.

0 comments:

Post a Comment