Constants and Variables in C Language
Constants in C language
A constant is any entity that does not change it’s value. Constants have two types which are
- Primary Constants (Integer Constant, Real Constant, Character Constant)
- Secondary Constants (Array, Pointer, Structure, Union, Enum etc)
Integer Constants Construction Rules
- An integar contant needs to have at least one digit.
- It must not have a decimal point.
- The Integer can be either positive or negative.
- If there is no sign before an integer then it is a positive integer.
- You can add commas or blanks within an integer constant.
- The integer constants range is -32768 to 32768.
Real Constant Construction Rules:
Real Constants are also known as Floating Point constants. These constants can be written in two forms which are Fractional form as well as Exponential form.
Here are the rules that you need to observe while constructung real constants expressed in the fraction form.
- Real constant must have a decimal point.
- It must have minimum of one digit.
- This constant can be positive or negative.
- The default sign of Real integer is positive.
- You can not add commas or blanks with a real constant.
Character Constant construction Rules:
- A Character constant is a single alphabet, digit ot a special symbol that has been enclosed into a single inverted commas. Both of the inverted commas should point to the left.
- Character constant’s maximum length can be one character.
C – Variables
A variable is an entity that may change during thr execution of the program. Variables names are the names given to the locations in the memory. The locations can contain integer, real or the character constants. The rules for constructing constants vary with the type of constant but the rules for constructing the variables in same.
Rules for Constructing Variable Names:
- A variable name is any of the combination of 1 to 31 alphabets, numbers or underscores.
- The character in the variable name must be an alphabet or underscore.
- You can not add any commaor blank within the variable name.
- You can not use any special symbol in a variable name other than an underscore.