Constants are values that do not change during program execution and include numeric constants like integers and floating point numbers, as well as string or character constants. Variables are identifiers that are used to refer to values that can change during program execution. Common variable types in C include integers, floating point numbers, characters, and strings. Variables must be declared with a data type before being assigned values and have naming conventions like starting with a letter and being less than 32 characters.
2. Constants
Any unchanged value in a program during the program
execution is called constant. Following are the constants in C
language.
• Numeric Constants
• String or Character Constants.
3. Numeric Constants
• Integer Constant
– An integer constant is a signed or unsigned whole
number.
– Example: -23 +356 46
– C language supports an integer constant in octal
(base 8) , decimal (base 10) and hexadecimal
(base 16). The default number system followed in
C language is decimal (base 10).
– An octal number is preceded by zero (0) and a
hexadecimal number is preceded by 0x or 0X.
4. • Real or floating point constant:
– Any signed or unsigned number with fractional
part is called real or floating point constant. A real
constant can be written in decimal or exponential
form.
– Example
– Decimal Form 0.254 +342.0 -
3.15
– Exponential Form 0.218e6 0.42e-32 -
1.0e12
– (0.218e6 means --> 0.218 x 10^6 and so on for all)
5. String or Character Constants
• Any string of characters enclosed in apostrophes or
quotes is called string constant or character constant.
There are two types of string constants.
• Single Character String Constant
• String of Characters Constant
6. Single Character String Constant
• Any letter or character enclosed in single apostrophe
is called single character string constant.
– Example: 'y' '$' '+'
7. String of Characters Constant
• Any string of characters consisting of letters, digits
and symbols enclosed in double quotes is called
string of characters constant.
– Example:
– "Total value is“ , “12 vyas fala”, “value is = “
8. Variables
• A variable is an identifier or a name which is used to
refer a value and this value varies or changes during
the program execution. A variable is written with a
combination of letters , numbers and special
characters _(underscore) with the first letter being
an alphabet. Maximum of 31 letters can be used to
write a variable.
– Example: x , fact , c22 , total_value
9. Important rules while writing a
variable in C Programming
• Upper and Lower case alphabets are taken differently, so
the variables SUM and sum are referring to different
values.
• No special characters other than underscore ( _ ) are
permitted.
• Some C compilers will not accept more than 8 characters.
So it is a good practice writing a variable with few letters
which makes it also convenient to write and use
• All variables used in a C program are declared with
appropriate data types before the variable is assigned any
value.
• Reserved words cannot be used as variables.