CONSTANTS:
The quantity which does not change during the execution of program is called constant.
'C' CONSTANTS: 2 TYPES
NUMERIC CONSTANTS: 2 TYPES
NON NUMERIC CONSTANTS: 2 TYPES
|
An integer constant is a sequence of digits without decimal point means whole number. It is prefixed with a plus or minus sign.The syntax of integer constant is
Sign | Digits |
where
Sign => optional Plus sign for positive number and minus sign for negative number
Digits => sequence of digits
EXAMPLE:
Sign => optional Plus sign for positive number and minus sign for negative number
Digits => sequence of digits
EXAMPLE:
500 , -23 , +56 etc.
FLOATING POINT CONSTANT:
A floating point constant is a sequence of digit with decimal point means real number. It is prefixed with plus or minus sign.The syntx of floating point constant is
Sign | Integer part | Decimal point | fractional part |
where
Sign => optional plus or minus sign
Integer part => digits before decimal point
Decimal point => dot symbol
fractional part => digits after decimal point
EXAMPLE:
+2.4 , -55.64 , 52.0 , 88.57 etc.
CHARACTER CONSTANT:
A single character constant is a single character enclosed with in pair of apostrophes.
EXAMPLE: 'c' , ' '(blank character) , '#' etc.
EXAMPLE: 'c' , ' '(blank character) , '#' etc.
STRING CONSTANT:
A string constant is a combination of character enclosed with in a pair of double quotes
EXAMPLE: " hi" , "200" etc.
VARIABLES:
The quantity that changes during the execution of program is called variable. The variable represent a particular memory location where the data can be stored. Variables are also called Identifiers.
EXAMPLE:
name , sum , average , age , state etc.
DECLARATION OF VARIABLES:
All variables must be declared before they are used in the program. The purpose of declaring variables is to reserve the memory require for the variables. The declaration is done in the declaration part of C program.The syntax for declaring variable is
Data_Type | Varlist | Semicolon |
where
Data_Type => such as int, float, char etc.
Data_Type => such as int, float, char etc.
Varlist => one or more variable
Semicolon => shows termination of declaration
EXAMPLE:
Semicolon => shows termination of declaration
EXAMPLE:
int abcd; int x;
float marks;
char a;
char name[10];
ASSIGNING VALUES TO VARIABLES:
ASSIGNING VALUES TO VARIABLES:
As we all know variables represent some memory location, where the data is stored. Each variable is associated with one or more values. The process of giving values to variables is known as assignment of values. The assignment operator"=" is used to assign a value to a variable. its syntax is
Variable_Name | = | value | ; |
where
Variable_Name => represents memory location where value is stored
Variable_Name => represents memory location where value is stored
value => constant or variable
EXAMPLE:
1. m=10;
2. int x=100;
0 Response to "Overview of Constants and Variables of C Language"
Post a Comment