Variables in c

Variables

variable is a name of the memory location where data value is stored. That data value may be change during the execution of a program.

Rules for defining variables

  • The first letter variable name must be alphabet (uppercase & lowercase), or underscore.
  • A variable can combinations of alphabets, digits and underscore.
  • In variable name commas or blanks space are not allowed.
  • In special symbol only underscore is allowed.
  • Keyword not use as variable name.
  • Uppercase letter and lower case letters are different. For example Sum is not same as sum or SUM.
  • Length should not be more than 8 characters because only first 8 character are treated as significant by many compilers.

Followings are some valid and invalid variable examples

Variable Name

Valid or Invalid

If invalid then reason

Number

Valid

 

First Number

Invalid

Blank space is not allowed

First_Number

Valid

 

number

Valid

 

Number$

Invalid

$ sign not allowed

int

Invalid

Keywords not allowed

int_sum

Valid

 

1num

Invalid

First letter digit not allowed

 

§  Note that use meaningful variable name in the program.


Post a Comment

0 Comments