Data types
Data Types in C Programming A data type is a predefined amount of memory allocated to store a single value. In C, these are defined using keywords. There are...
Data Types in C Programming A data type is a predefined amount of memory allocated to store a single value. In C, these are defined using keywords. There are...
A data type is a predefined amount of memory allocated to store a single value. In C, these are defined using keywords. There are several types of data types, each with its own specific characteristics:
1. Integer Types:
int is the most basic data type, representing whole numbers with no decimal points.
Example: int age = 25;
2. Float Types:
float is used for real numbers with decimal points.
Example: float weight = 18.5;
3. Character Types:
char is used for single characters (e.g., 'a', 'b', 'c').
Example: char name[5] = "John";
4. Boolean Type:
bool is used to represent true or false values.
Example: bool is_active = true;
5. Structures:
A structure is a collection of variables of different data types grouped together.
Example:
c
struct person {
int age;
float height;
char name[50];
};
struct employee {
int employee_id;
char name[50];
float salary;
};
6. Unions:
A union is a single data type that can hold either an int or a float.
Example:
c
union data {
int number;
float value;
};
7. Arrays:
An array is a collection of elements of the same data type stored in contiguous memory locations.
Example:
c
int numbers[10];
8. Pointers:
A pointer is a variable that stores the memory address of another variable.
Example:
c
int number = 10;
int *ptr = &number; // ptr now stores the address of 'number'
Understanding data types is crucial for effective C programming, as it allows you to choose the right data type for specific tasks and optimize your code for performance