C Variables and Their Types

·

In C, a quantity which may vary during program execution is called a variable. Variable names are names given to locations in the memory of computer where different constants are stored. These locations can contain integer, real or character constants. In any language the types of variables that it can support depends on the type of constants that it can handle. This is because a constant stored in a location with a particular type of variable name can hold only that type of constant. For example, a constant stored in a memory location with an integer variable name must be an integer constant. One stored in location with a real variable name must be a real constant and the one stored in location with a character variable name must be a character constant.

Rules for Variable Names

(i) A variable name is any combination of 1 to 8 alphabets, digits or underscores.
(ii) The first character in the variable name must be an alphabet
(iii) No commas or blanks are allowed within a variable name.
(iv) No special symbol other than an underscore(as in gross-sal) can be used in a variable name.
e.q. si_int
m_hra
pop_e_89
C compiler is able to distinguish between the variable names, by making it compulsory for you to declare the type of any variable name you wish to use in a program. This type of declara- tion is done at the beginning of the program.

Following are the examples of type declaration statements:

e.q. int si, m-hra;
float bassal;
char code;

C Keywords
Keywords are the words whose meaning has already been explained to the C compiler. Keywords can not be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. The keywords are also called ‘Reserved words’. There are 32 keywords available in C.
following is list of keywords in C.

  1. auto
  2. double
  3. if
  4. static
  5. break
  6. else
  7. int
  8. struct
  9. case
  10. enum
  11. long
  12. typedef
  13. const
  14. float
  15. register
  16. union
  17. continue
  18. far
  19. return
  20. unsigned
  21. default
  22. for
  23. short
  24. void
  25. do
  26. goto
  27. signed
  28. white

About Me

Blog Archive