In this guide, we’ll explore the different data types in C. Data types are essential because they tell the compiler what kind of data a variable can hold.
Understanding Data Types in C
Types of Data Types in C
C supports several fundamental data types:
- int: Used to store integer values (whole numbers).
- Example:
int age = 30;
- Example:
- float: Used to store single-precision floating-point numbers (decimals).
- Example:
float salary = 2500.50;
- Example:
- double: Used to store double-precision floating-point numbers for more accuracy.
- Example:
double pi = 3.14159;
- Example:
- char: Used to store a single character.
- Example:
char initial = 'A';
- Example:
- void: Indicates that a function does not return a value or that a pointer does not have a specific type.
- Example:
void myFunction() { /* code */ }
- Example:
Understanding these data types is crucial for defining the type of data your variables can hold, which in turn helps in writing efficient C programs.
×