Variables and Constants

In the previous chapter we have learnt about basic concept of Tokens, Keywords, Identifier, compilation and execution process of c etc. In this chapter we are going to learn about the Variables and Constants in C Programming.

Variables and Constants in C programming:

Variable:

As the name suggest, Variable is a memory location that can be used to store data whose values can be altered in program based on certain condition.

Syntax:
Data_type identifier_name;

Variable Example:

In the above program v1, v2, sum are the variables which holds the value which can be changed.

Constants:

Constants are the data values which cannot be altered or modified throughout the program whose value is fixed for the entire programs. Constants are of following type:

    1. Integer constant
    2. Character constant

variables and constants

  1. String constant
  2. Floating constant

Integer constant:
There are of three types of integer constant

  1. Decimal constants-0,1,2,3,4,5,6,7,8,9(base 10).
  2. Octal constants-0,1,2,3,4,5,6,7 (base 8).
  3. Hexadecimal constants- 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F(base 16).

Character constant:
These are generally written under single quote.
For example: ‘A’,’B’,’>’ etc.

String constant:
These constants are written under double quotes.
For example:”[email protected]

Floating constants:
These are constants used to represent floating point values. Floating constants have these type: float, double or long double, exponential
For example:
9.5f –float constant
9.5- double constant
9.5l- long double constant
3.5e0- exponential form double constant

“Click here to access free online test powered by Quick Solution.”

Leave a Reply