![]() |
VOOZH | about |
Data types form the foundation of data representation in C. Every variable in C must be associated with a data type that defines the kind of value it can store and how the compiler handles it.
Data types in C are broadly classified into three categories:
Primitive data types are the basic built-in data types in C used to store simple values like integers, characters, and floating-point numbers.
Format specifiers are the symbols that are used for printing and scanning values of given data types.
var = 22
ch = A
val = 12.450000
val = 1.452100
Hello, welcome!
Derived data types are created from primitive data types.
An array stores multiple values of the same type in contiguous memory locations.
int arr[5] = {1, 2, 3, 4, 5};
A pointer stores the memory address of another variable.
int x = 10;
int *ptr = &x;
Functions are also considered derived types based on return type and parameters.
int add(int a, int b) {
return a + b;
}
User-defined data types allow programmers to create custom data structures.
A structure groups related variables under one name
struct Student {
char name[50];
int age;
};
A union allows multiple members to share the same memory location.
union Data {
int i;
float f;
};
Enum is used to define named integer constants.
enum Day {
MON, TUE, WED, THU, FRI, SAT, SUN
};
The size of the data types in C is dependent on the size of the architecture, so we cannot define the universal size of the data types. For that, the C language provides the sizeof() operator to check the size of the data types.
The size of int: 4 The size of char: 1 The size of float: 4 The size of double: 8
Different data types also have different ranges up to which can vary from compiler to compiler. If you want to know more about ranges refer to this Ranges of Datatypes in C.
Note: The long, short, signed and unsigned are datatype modifier that can be used with some primitive data types to change the size or length of the datatype.