Identifiers & variables
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
|
Types:
There are two types of identifiers:
·
Standard
identifiers.
·
User-defined
identifiers.
Standard
identifiers:
Like reserved words, standard
identifiers have special meaning in C, but these can be redefined to use in the
program for other purpose, however this practice is not recommended.
User-defined
identifiers:
User need to access memory locations
for storing data and program results. For this purpose memory cells named that
are called user-defined identifiers.
*C is a case
sensitive language. So, SQUARE_AREA and square_area are two different
identifiers.
Keyword:
Keyword or reserved words are the words, which have
pre-defined meaning in any high level programming language.
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.
Rules of naming
Variable
·
A
variable name consists of letters, numbers and underscore.
·
The first
character is must be letter.
Example: home#2, winner_2 are valid.
#home, 2winner are invalid.
·
C
is a case sensitive language. So, SQUARE_AREA and square_area are two different
variables.
·
Keywords
are not used as variables.
·
First 31
characters are significant. If two variables has first 31 characters are same
so the compiler cannot be recognized difference between them.
·
Blank
spaces are not allowed between the names of variable.
·
A
variable can only declared for one data type.
Comments
Post a Comment