Our previous article on Data Types describes the use of data types in various programming languages. Data types in C are declarations for memory addresses or variables that determine which operators and functions can be applied to the addresses and variables.
C provides basic arithmetic data types for storing integers and floating-point numbers, as well as the syntax needed to create fields and compound types. Several header files in the C standard library also offer definitions of other data types, each of which has certain useful properties. In the C programming language, understanding data types is fundamental for writing efficient and bug-free code. Sometimes, while writing code, a statement may not be illegal to the compiler but in reality, it may not get executed because of error related to data type.
Basic Data Types
Integer Types
---
Integers represent whole numbers without any fractional part. In C, integers can be classified into several types based on their range and storage size:
- char: Represents a single byte (typically 8 bits) capable of storing a character or small integer value.
- short: Typically a 16-bit integer used when memory is a constraint.
- int: Usually a 32-bit integer on most modern systems. It’s the most commonly used integer type.
- long: A 32-bit or 64-bit integer, depending on the system architecture.
- long long: Introduced in the C99 standard, provides at least 64 bits of precision.
Floating-Point Types
Floating-point types are used to represent real numbers with a fractional part. In C, they are typically classified into two types:
- float: Single-precision floating-point type, occupies 4 bytes and provides about 6 decimal digits of precision.
- double: Double-precision floating-point type, occupies 8 bytes and offers about 15 decimal digits of precision.
Void Type
The void type specifies that no value is available. It is commonly used to indicate that a function does not return any value or to declare generic pointers.

Derived Data Types
Arrays
Arrays are collections of elements of the same data type stored in contiguous memory locations. They provide a convenient way to store and manipulate a fixed-size sequence of elements.
1 | int numbers[5] = {1, 2, 3, 4, 5}; |
Pointers
Pointers are variables that store memory addresses. They enable dynamic memory allocation and manipulation of data structures like arrays and strings.
1 2 3 | int *ptr; int num = 10; ptr = # // ptr now points to the memory address of num |
Structures
Structures allow you to group multiple variables of different data types under a single name. They are especially useful for organizing related data.
1 2 3 4 5 | struct Person { char name[50]; int age; float height; }; |
Union
A union is a special data type that allows storing different data types in the same memory location. Only one member of the union can be accessed at a time.
1 2 3 4 5 | union Data { int i; float f; char str[20]; }; |
Enumerations
Enumerations (enums) enable you to define a set of named integer constants. They provide a way to create symbolic names for integral values, improving code readability.
1 2 | enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }; enum Weekday today = Tuesday; |
Modifiers
C provides various type modifiers to alter the storage size and range of basic data types:
- signed and unsigned: Modifiers used with integer types to specify whether they can hold negative values or only non-negative values.
- short and long: Alter the storage size of integer types, where short reduces the size and long increases it.
- const: Specifies that a variable’s value cannot be changed once initialized.
- volatile: Indicates that a variable’s value may be changed at any time by external sources, thus preventing compiler optimization.
Conclusion
Understanding data types is fundamental for writing robust and efficient C programs. By selecting appropriate data types, you can optimize memory usage, improve code readability, and ensure compatibility across different platforms. Mastery of data types empowers programmers to write clearer, more efficient, and maintainable code in the C programming language.