In C programming language, data types refer to the different types of values that can be stored and manipulated by a program. C has several built-in data types that can be classified into the following categories:
- Integer Types: These are used to store whole numbers (integers). The most commonly used integer types in C are:
- int: Used to store integers. Its size is usually 4 bytes.
- short: Used to store small integers. Its size is usually 2 bytes.
- long: Used to store large integers. Its size is usually 4 bytes, but it may be larger depending on the implementation.
- long long: Used to store very large integers. Its size is usually 8 bytes.
- Floating-point Types: These are used to store real numbers (numbers with decimal points). The most commonly used floating-point types in C are:
- float: Used to store single-precision floating-point numbers. Its size is usually 4 bytes.
- double: Used to store double-precision floating-point numbers. Its size is usually 8 bytes.
- Character Types: These are used to store single characters. The most commonly used character type in C is:
- char: Used to store single characters. Its size is usually 1 byte.
- Boolean Type: This is used to represent logical values. In C, the boolean type is not built-in, but it can be defined using an enum or a typedef.
- _Bool: A built-in type, introduced in the C99 standard, that is used to store logical values (true or false). Its size is usually 1 byte.
In addition to these built-in data types, C also allows the creation of user-defined data types using structs and unions.
Basic Data Types:
In C programming language, the basic data types are:
- int: Used to store integer values. Its size is usually 4 bytes.
- char: Used to store character values. Its size is usually 1 byte.
- float: Used to store floating-point values with single precision. Its size is usually 4 bytes.
- double: Used to store floating-point values with double precision. Its size is usually 8 bytes.
- void: Used to represent the absence of a data type. It is commonly used to declare functions that do not return a value.
These basic data types can be combined to form more complex data types using arrays, structures, and pointers. For example, an array of integers can be declared as “int array[10]” and a structure containing multiple data types can be declared as “struct myStruct { int i; char c; float f; }”. Pointers can also be used to manipulate these data types and to create dynamic data structures.