Identifiers & Variables in C++


Identifier:

The C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores, and digits (0 to 9).
C++ does not allow punctuation characters such as @, $, and % within identifiers. C++ is a case-sensitive programming language. Thus, Manpower and manpower are two different identifiers in C++.
Here are some examples of acceptable identifiers
Mohd
Piyush
abc
move_name
a_123
myname50
_temp
j
a23b9
retVal

Variable:

            Variables are named memory location (memory cells), which are used to store program’s input and its computational results during program execution.
The variables are created in memory (RAM) therefore the data is stored in them temporarily.

Declaration:

            In C++ all variables are must declare before being used. The compiler report an error if any undeclared variable is used.
A variable is declared by specified its type (data type) and name.
·         A variable declaration does not set aside memory location for the data to be stored.
·         It just informs the compiler the name of variable and its data type.

Syntax:

            Data type        variable name;

Example:

            Int number;

Definition:

            “In definition of variable that set aside the location of variable in memory.“

Initializing the variable:

                        “Assigning a value to a variable at the time of its declaration is called initializing a variable.”  

Garbage Value:

            When a variable is declared, the compiler set aside some memory space for it. This allocation memory space, may contain data meaningless to the program called garbage value.


Comments

Popular Posts