Constants, Variables & Data Types 2
Constants, Variables & Data Types 2
❖ C is portable.
4
CHARACTER SET
5
BASIC STRUCTURE OF C PROGRAM
Documentation section
Header File
Constants and Global variables Declaration
Main () function section
{
Statement(s);
}
User Defined functions and procedures with their body
6
CHARACTER SET
7
C TOKEN
✓ The smallest individual unit in a C program is known as C
token.
• Keywords (float,while)
• Identifier(main,amount)
• Constants(-15.2, 10)
• String(“abc”, “hello”)
• Special Symbols ([ , ] , *, ! etc)
• Operators (+,-, *,/) 8
KEYWORD
❖ Documentation section:
❖ Constant Declaration:
There are some variable that are used more than one function.
Such Variables are called global variable and that is outside all
the function. This section also declares the entire user define
functions.
✓ Integer
✓ Real
✓ Character
14
✓ String
INTEGER CONSTANT
16
CHARACTER CONSTANT
✓ Character constant is a single character enclosed in a single
quotation mark.
Example: ‘a’
✓ Back slash constants are the special type of character constants
which actually consists of two characters. These are known as
escape sequences.
✓ The combination of backslash and a character is known as escape
sequence.
Escape sequence start with back slash ‘\’ character.
Example: ‘’Hello’’
Constant can be declared in a program using count
keyword.
18
V A R IA B L E
A variable is a name which is used to store a temporary value.
The value of the variable may changes during execution of the
program.
✓ The variable name may consist of letters (A-Z, a-z), digits (0-9)
and underscore symbol ( _ ).
Example: int no_1; / int no1; / int NO1;
✓ The variable name must begin with a letter. Some system
permit underscore as a first character.
Example: int 1NO; is not valid
✓ This can be done with the help of “type definition”. This allows the
user to define an identifier that would represent an existing data
type.
✓ We can use this identifier to declare the variables.
✓ Syntax:
24
VARIABLE DECLARATION AND
ASSIGNING VAL UES TO VARIABLES
‘ C’ varible must be declared before using it in program.
Example:
int count;
int no1,no2,no3;
26
double ratio;
ASSIGNING VAL UES TO A VARIABLE
✓ VariableName=Value;
27
EXAMPLE
int a;
a=10;
DataType VariableName=Value;
Syntax:
28
DataType VariableName=Value
SYMBOLIC CONSTANTS
Syntax
const DataType
ConstantName=Value;
31
EXAMPLE
32
VOLATIL E
✓ For Example:
Enum week_day {Monday, Tuesday, Wednesday};
Here, week_day is a user defined data type.
✓ Using this data type we can declare another variable of this data
type.
34
✓ Enum week_day start, end;
✓ Here, start and is the variable of type week_day.
✓ The complier will automatically assign the value 0 to the Monday,
1 to the Tuesday and 2 to the Wednesday.
✓ For Example:
✓ Register:
✓ The variable declared as register is only visible to the function in
which it is declared .But the value of the variable is stored in the
register to it can be accessed faster as compared to other
variable.
37
✓ It is also known as local variable.
Thank You….
38