Posted by admin at July 9, 2021
Data types in c refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted.
The types in C can be classified as follows −
Sr.No. | Types & Description |
---|---|
1 | Basic TypesThey are arithmetic types and are further classified into: (a) integer types and (b) floating-point types. |
2 | Enumerated typesThey are again arithmetic types and they are used to define variables that can only assign certain discrete integer values throughout the program. |
3 | The type voidThe type specifier void indicates that no value is available. |
4 | Derived typesThey include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types. |
In this example, you will learn to evaluate the size of each variable using sizeof operator.
To understand this example, you should have the knowledge of the following C programming topics:
C Data Types
C Variables, Constants and Literals
C Input Output (I/O)
The sizeof(variable)operator computes the size of a variable. And, to print the result returned by sizeof, we use either %lu or %zu format specifier.
Program to Find the Size of Variables
include
int main() {
int intType;
float floatType;
double doubleType;
char charType;
printf("Size of int: %zu bytes\n", sizeof(intType));
printf("Size of float: %zu bytes\n", sizeof(floatType));
printf("Size of double: %zu bytes\n", sizeof(doubleType));
printf("Size of char: %zu byte\n", sizeof(charType));
return 0;
}
Output
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
Comments