In C programming, **Data Types** are declarations for variables. This determines the type and size of data associated with variables. Since C is a statically typed language, you must specify the data type of a variable at the time of declaration so the compiler can allocate the correct amount of memory.
C provides a set of built-in data types that handle various kinds of information, from simple characters to large decimal numbers. These are known as Primary Data Types.
The size and range of these data types can vary depending on the compiler and the architecture of the computer (32-bit vs 64-bit). However, the standard sizes are as follows:
| Data Type | Size | Format Specifier | Description |
|---|---|---|---|
int |
2 or 4 bytes | %d or %i | Stores whole numbers. |
float |
4 bytes | %f | Stores fractional numbers (6 decimals). |
double |
8 bytes | %lf | Stores fractional numbers (15 decimals). |
char |
1 byte | %c | Stores a single character/ASCII value. |
C allows you to use Type Modifiers to change the range or size of the basic data types to suit your needs better. This is useful for optimizing memory.
long int or long double).Here is how you use different data types in a real program to store diverse information:
If you are ever unsure about how much memory a data type is occupying on your specific system, C provides the sizeof() operator. This is extremely helpful for writing platform-independent code.
In C, characters are actually stored as integers internally. Every character has a corresponding **ASCII value**. For example, 'A' is stored as 65. You can even perform mathematical operations on characters!
double when a float is sufficient wastes memory, which can slow down large-scale applications.