Data Types in C Programming
Understanding C Data Types and
Their Usage
What are Data Types in C?
• Data types define the type of data a variable
can store.
• They help in memory allocation and data
interpretation.
• C provides a rich set of built-in and user-
defined data types.
Classification of Data Types in C
• Basic (Primitive): int, char, float, double
• Derived: array, pointer, function, structure
• Enumeration: enum
• User-defined: struct, union, typedef
• Void: void
Basic Data Types
• int – Integer numbers (e.g., 10, -3)
• char – Single character (e.g., 'A')
• float – Decimal number (e.g., 3.14)
• double – Larger and more precise float
Size of Basic Data Types
• int: 4 bytes
• char: 1 byte
• float: 4 bytes
• double: 8 bytes
Type Modifiers
• short – Smaller range integer (2 bytes)
• long – Larger range or precision
• signed – Allows negative and positive values
• unsigned – Only positive values, larger upper
limit
Examples of Modified Types
• short int x; // 2-byte integer
• unsigned char ch; // 0 to 255 range
• long double d; // High precision floating-
point
Derived Data Types
• Array – Group of same data type (int
marks[5];)
• Pointer – Stores address of another variable
(int *ptr;)
• Function – Group of statements performing a
task
• Structure – Group of variables of different
types
Void Data Type
• Used to specify no value.
• Commonly used in functions that return
nothing.
• Example: void greet() { printf("Hello"); }
User-defined Data Types
• Create your own data types using:
• struct – Structure
• union – Union
• enum – Enumeration
• typedef – Alias for another type
Example: struct and typedef
• typedef int age;
• struct student {
• int id;
• char name[20];
• };
• Data types define the kind of data stored in a
variable.
• They ensure proper memory use and type
safety.
• Modifiers and custom types add flexibility.
• Mastering data types is fundamental in C
programming.