A program is a set of instructions. Instructions are also
known as commands or statements. They are the sentences in program. Just like
any other language C also provides variety of instructions.
Types of instructions
Data
type declaration instruction
Input/Output instruction
Arithmetic instruction
Control instruction
Input/Output instruction
Arithmetic instruction
Control instruction
Data type declaration
instruction
From the list of keywords few are designed to use in
declaration instruction. They are required to declare variables and functions.
These keywords are
int, float, char,
double, void
Here we are only concern with variable declaration.
Declaration of functions will be deal in later chapter.
Consider the following statements
int x=5, y;
float k=2.34;
char a=’y’, ch;
These are examples of data type declaration instruction.
Compiler when read these instructions, it would get aware of four things:
1)
Name of the
variables
Here names are x ,y, k, a, ch
2)
Size of
memory block
Size of int type block is 2 bytes,
size of float block is 4 bytes, size of char block is 1 byte, size of double
block is 8 bytes
3)
Type of
content
int variable can contain integer
constant, float and double variable can contain real constant and char variable
can contain character constant.
4)
Value in
variable
x contains 5, k contains 2.34 and a
contains ‘y’.
Variables y and ch are not
initialized but they are not empty. They contain unpredictable values which are
of no use in the program, so called them garbage values.
Modifiers
Modifiers are the keywords used to modify the properties of
data type.
Modifiers are short, long, signed, unsigned.
Here is the list of all possible combination of use of
modifiers with data type:
Create variables to
store integers:
int, short int, signed int, long int, unsigned
int, unsigned short int, unsigned long int.
Create variables to
store real constant
float, double, long
double
Create variables to
store character constant
char, unsigned char
Modifiers affect size of data type (short and long), data
range (signed and unsigned)
Following data type chart helps you to learn different
properties modified in data type
|
Type
|
Size
|
Format
specifier
|
Content Type
|
Range
|
|
unsigned char
|
8 bits
|
%c
|
Character
|
0 to 255
|
|
Char
|
8 bits
|
%c
|
Character
|
-128 to 127
|
|
unsigned int
|
16 bits
|
%u
|
Integer
|
0 to 65,535
|
|
short int
|
16 bits
|
%d
|
Integer
|
-32,768 to 32,767
|
|
Int
|
16 bits
|
%d
|
Integer
|
-32,768 to 32,767
|
|
unsigned long
|
32 bits
|
%lu
|
Integer
|
0 to 4,294,967,295
|
|
Long
|
32 bits
|
%ld
|
Integer
|
-2,147,483,648 to 2,147,483,647
|
|
Float
|
32 bits
|
%f
|
Real
|
1.1754*(10^-38) to 3.4028* (10^+38)
|
|
Double
|
64 bits
|
%lf
|
Real
|
2.2250 * (10^-308) to 1.7976 * (10^+308)
|
|
long double
|
80 bits
|
%Lf
|
Real
|
3.4 * (10^-4932) to 1.1 * (10^4932)
|
No comments:
Post a Comment