Lecture Handout 4
Lecture Handout 4
A data type specifies the type of data that a variable can store such as integer, floating,
character, etc.
1 Basic Types
They are arithmetic types and are further classified into: (a) integer types and (b) floating-point
types.
2 Enumerated types
They are again arithmetic types and they are used to define variables that can only assign certain
discrete integer values throughout the program.
4 Derived types
They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e)
Function types.
The basic types and the enumerated types together make up the arithmetic types.
The arithmetic types and the pointer types together are called the scalar types.
Finally, array types and structure types are referred to collectively as the aggregate types.
Integer Types:
Signed Values- if we want to take signed or unsigned values both we will go for signed.
Unsigned Value- if we only looking for positive or negative number we use Unsigned.
The following table provides the details of standard integer types with their storage sizes and
value ranges −
Floating-Point Types
C also includes special numeric types that can represent nonintegers with a decimal
point in any position. The standard floating-point types for calculations with real numbers are as
follows:
Float:
Double:
long double:
In C, arithmetic operations with floating-point numbers are performed internally with double or
greater precision. For example, the following product is calculated using the double type.
float height = 1.2345, width = 2.3456; // Float variables have single
// precision.
double area = height * width; // The actual calculation is
// performed with double
// (or greater) precision
The following table provide the details of standard floating-point types with storage sizes and
value ranges and their precision −
return 0;
}
Output:
• double _Complex
Enumerated Types:
Enumerations are integer types the definition of an enumeration begins with the
keyword enum,
each value:
enum [identifier] { enumerator-list };
The following example defines the enumerated type enum color:
enum color { black, red, green, yellow, blue, white=7, gray };
#include<stdio.h>
int main()
day = Sun;
printf("%d",day);
return 0;}
OUTPUT:
The Type void
The type specifier void indicates that no value is available. Consequently, you
cannot declare variables or constants with this type. You can use the type void for the purposes
described in the following sections.
3 Pointers to void
A pointer of type void * represents the address of an object, but not its type. For example, a memory
allocation function void *malloc( size_t size ); returns a pointer to void which can be casted to any
data type.
int a = 10;
char b = 'x';
#include<stdio.h>
int main()
int a = 10;
return 0;
Output:
10