Deta types
Data types:
C language is rich in its data types. ANSI supports three classes of
data types.
1) Primary or fundamental data types.
2) Derived Data types.
3) User-defined data types.
1) Fundamental Data types:
All C compilers support five fundamental data types.
Integer (int)
Character (char)
Floating point (float)
Double-precision point (double)
Void
i. Integer types:
Integer types are whole numbers with a range of
values supported by particular machine. If we
use a 16 bit word length, the size of the integer
value is limited to the range -32768 to +32767.
C has three classes of integer storage namely
Short int
Int
Long int
Short int represents small values than int
and int represents small value than long
int. or we can say that
Short int < int < long int
Here 1 byte = 8 bits.
Signed int is able to represent negative values.
Unsigned int can represent non-negative values (positive
values).
ii. Floating point types:
Floating point numbers are stored in 32 bits, with
6 digits of precision.
Floating point numbers are defined in C by
keyword float.
When float is not sufficient double can be used
and when double is not sufficient long double
can be used.
The following table provide the details of
standard floating point types with storage size
and value ranges and their precision,
iii. Void types:
The void type has no values. This is usually used
to specify the types of functions.
The types of function is said to be void when it
does not return any values to the calling
function.
iv. Character types:
A single character can be defined as character
(char) type data.
Characters are usually stored in 8 bits (1 byte) of
internal storage.
While unsigned char have values between 0 to
255, sign char have values from -128 to 127.
Declaring & initialization of C variable:
Declaration:
Variables must be declared in C program before use.
In C language variable is declared using following syntax:
Syntax:
Data_type variable_name;
Example:
int sum;
Here, int is data types and sum is the name of
variable.
Multiple variables can be declare like,
Example:
int sum, total, a;
float p, r;
Initialization:
o Variable initialization means assigning a value to the variable.
Example:
int sum=30;
Here variable sum is declared and at the same time it is assigned a value 30.
Declaring variable as constant
Variable can be declared as constant using keyword const.
Example:
const int sum =30;
OR
int const sum=30;
Here, Variable sum is declared as const it means that
the value of variable sum cannot be changed latter in
program.
Any attempt to change the value of sum will result in
error.
Const keyword can be used before or after data type.
Comments
Post a Comment