Data types in C
Data Types in C Data types define the type of information a variable can hold. In C, there are several data types, which are pre-defined by the compiler. The...
Data Types in C Data types define the type of information a variable can hold. In C, there are several data types, which are pre-defined by the compiler. The...
Data types define the type of information a variable can hold. In C, there are several data types, which are pre-defined by the compiler. These types specify the allowed values a variable can take on.
Primitive Data Types:
int: This is the most basic data type, representing whole numbers.
float: This type represents floating-point numbers, with decimal points.
char: This type represents single-byte characters, such as letters and numbers.
bool: This type represents true or false values.
Compound Data Types:
struct: A structure is a collection of variables of different types, grouped together under a single name.
union: A union is a data type that can hold only one of a set of related types.
array: An array is a contiguous memory location containing multiple variables of the same type.
Example:
c
// Define a variable of type int
int age = 25;
// Define a variable of type float
float weight = 78.5;
// Define a variable of type char
char name[10];
// Define an array of integers
int numbers[5] = {1, 2, 3, 4, 5};
Key Points:
Data types are declared using keywords like int, float, char, etc.
The int data type is used for storing whole numbers, while float is used for representing decimal numbers.
char is used for storing single characters, while struct and union are used for more complex data types.
Arrays are used to store multiple values of the same type in a contiguous memory location