In C programming language, data types specify the type of data that a variable can hold. Here are some common data types in C:
int: Used to store integers (whole numbers).
Example: int num = 10;
float: Used to store single-precision floating-point numbers (decimal numbers).
Example: float pi = 3.14;
double: Used to store double-precision floating-point numbers (larger decimal numbers).
Example: double largeNum = 123456789.123456789;
char: Used to store single characters or small integers.
Example: char letter = 'A';
void: Represents the absence of a type. Typically used as the return type of functions that do not return a value.
Example: void func();
Array: A collection of elements of the same data type arranged in contiguous memory locations.
Example: int numbers[5] = {1, 2, 3, 4, 5};
Pointer: A variable that stores the memory address of another variable.
Example: int *ptr;
Structure (struct): A user-defined data type that allows storing multiple variables of different types under one name.
Example:
Union: Similar to a structure but uses the same memory location for all its members.
Example:
Enumeration (enum): A user-defined data type used to assign names to integral constants.
Example:
signed: Specifies that a variable can hold both positive and negative values (default for int
and char
).
unsigned: Specifies that a variable can hold only non-negative values.
long: Increases the size of the data type (longer range and precision).
short: Decreases the size of the data type (shorter range and precision).
C provides a rich set of data types that allow programmers to work with various types of data efficiently. Understanding these data types and their characteristics is essential for writing robust and efficient C programs.