Type: A type is a set of values and operations on those values.
For example: Light switch can be compared to a type. It has two values( on and off), only two operations can be performed (Switch on and Switch Off)
A data type defines a set of values and the operations on that can be performed on them. Moreover a data type tells to the compiler
- What type of data the program can handle
- How much memory is needed for that data.
- What type of operations that can be performed on those data.
1.Basic Data Types
i) Void Data type
- Designated by 'void' keyword.
- Used in front of a function which does not return any value.
- Used to create generic pointers.
ii) Integral Data type
The C language has three integral data types.
a) Boolean data type
- Used to represent two values 'true' or 'false'
- Designated by the keyword 'bool'
b) Character Data type
The characters are used to form words, numbers and expressions depending upon the computer on which the program runs. There are two types of character types.
- Signed characters which occupies one byte in memory and range from -128 to 127
- Unsigned characters which occupies one byte in memory and range from 0 to 255
- The format specifier used is %c
c) Integer Data type:
An integer is a number without fractional part. C supports 4 different types of integer types.
Type |
Size in bytes |
Range |
Format specifier |
Short int |
1 |
-27 to 27-1 |
%hd |
Int |
2 |
-215 to 215-1 |
%d |
Long int |
4 |
-231 to 231-1 |
%ld |
Long long int |
8 |
-261 to 261-1 |
%ud |
d) Floating point type:
i) real data type
real data type represents the real numbers; A number with decimal part.
ii) imaginary data type
An imaginary number is used extensively in mathematics and engineering. An imaginary number is a real number which is multiple of square root of -1
iii) Complex numbers type
A complex number is a combination of real and imaginary number.
2. Derived Data Types
Derived Data types are derived from the basic data types.
Examples: Arrays, functions, pointers
3.User Defined Data types:
C allow us to define our own data types such as structures and unions.These are called user defined data types because the programmer or user creates them according to their needs.
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.