Skip to main content

INTRODUCTION TO VARIABLES IN 'C' LANGUAGE..

     INTRODUCTION TO VARIABLES IN 'C'.

 VARIABLES:

           While learning C programming you might have encountered the word variables. What are variables? Variables are names given to every defined value of a program. These names are given locations capable of storing temporary data within a program. This data is stored in the internal memory (RAM) of the computer. This data can be modified, stored or displayed whenever needed. The size of a variable depends upon the type of the data and the range of the datatype. The size of a variable varies according to the datatype. 



         For example, on a personal computer the size of an integer variable is 2 bytes, 4 bytes for float variable, 1 byte for character variable and for double variable is 8 bytes. Let me make this more simple. let`s take an integer variable i.e. int a,b,c; here integer has 3 variables a,b and c. As we saw above for a single integer variable occupies 2 bytes of space, and here we have 3 int variables. Therefore, the amount of space required for them is 6 bytes because 2*3=6 (* = multiplication).

         The name of a variable can be composed of letters, digits, and underscore character. It must begin with either a letter or an underscore. In 'C' programming Upper and Lowercase letters are distinct because C is case-sensitive. It means functions written within C programming must me written in small letters. 


     

 TYPES OF C VARIABLES:

           A particular type of variable can hold only the same type of constant. For example, an integer variable can hold only an integer constant, a real variable can hold only a real constant and a character variable can hold only a character constant. The rules for constructing different types of constants are different. However, for constructing variable names of all types, the same set of rules applies. These rules are given below. 



RULES FOR CONSTRUCTING VARIABLE NAMES.

  • A variable name is any combination of 1 to 31 alphabets, digits or underscores. Some compilers allow variable names whose length could be up to 247 characters. Do not create unnecessarily long variable names as it adds to your typing efforts and may result in errors. 
  • The first character in the variable must be an alphabet or an underscore(_).
  • No commas or blanks are allowed within a variable name.
  • No special symbol other than an underscore can be used in a variable name.











       
 

Comments