Constants and Variables
Constants
The quantity which does not change during the execution of a program is known as a constant.
Two types of constants – numeric constants(integer constants and floating-point constants) and non-numeric constants(character constants and string constants).
Variables
The quantity that changes during the execution of a program is called a variable.
Also caled identifiers.
The variables represent a particular memory location where data can be stored.
All variables must be declared before they are used in a C program.
The purpose of declaring variables is to reserve the amount of memory required for the variables.
The declaration is made in the declaration part of a C program.
Syntax – Data_type|Varlist|Semicolon
Assignment of values
The process of giving values to variables is called the assignment of values.
Assignment operator ‘=’.
Syntax – variable_name|=|value|;
There are two methods of assigning values to variables – within the declaration section & in the executable part of a program.
Assigning variables within the declaration is called initialization.
Data Types
Data types indicate the type of data that a variable can hold.
- Built-in data types
- Derived data types
- User-defined data types
Built-in data types
They are basic or primitive data types and designate a single value.
- integer
- real or floating-point number
- double precision real number
- characters
One and only one non-specific data type called ‘void’.
Backslash constants
A backslash constant is a combination of two characters in which the first character is always the backslash(\) and the second character can be any one of the characters a, b, f, n, r, t, v, ‘, ”, \ and 0.
Also called escape sequences.
Used in the output statements.
Type Modifiers
The basic data types except void can be modified using a series of type modifiers to fit the requirement of a particular program more closely.
These modifiers are called qualifiers.
- signed
- unsigned
- short
- long
Two new data type modifiers in ANSI – const and volatile.
const – to provide constant-ness to the value of the variables, during the execution of a program.
volatile – to instruct the compiler that the value of the variable may be modified at any time by an outside factor.
Symbolic Constants
A symbolic constant is a name that substitutes a numeric constant, a character constant or a string constant.
Symbolic constants are defined using preprocessor statement ‘#define’.
Delimiters
They limit the boundary between the basic elements of a program.
They are also called separators.
Related posts:








Leave your response!