-
Notifications
You must be signed in to change notification settings - Fork 2
/
DataTypes.txt
42 lines (36 loc) · 2.16 KB
/
DataTypes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Data types in C are used to specify the type of data that a variable can hold. The data type determines the amount of memory allocated to the variable, the range of values it can hold, and the operations that can be performed on it.
C provides several built-in data types, including integers, floating-point numbers, characters, and Boolean values. Here are some examples:
1. Integer data types:
- int: This is the most commonly used data type in C, representing integer values. It typically uses 4 bytes of memory and can hold values from -2147483648 to 2147483647. For example:
```
int x = 10;
```
- short: This is a smaller integer data type that uses 2 bytes of memory and can hold values from -32768 to 32767. For example:
```
short y = 5;
```
- long: This is a larger integer data type that uses 8 bytes of memory and can hold values from -9223372036854775808 to 9223372036854775807. For example:
```
long z = 100000;
```
2. Floating-point data types:
- float: This data type is used to represent single-precision floating-point values, which are decimal numbers with a range of approximately 3.4E-38 to 3.4E+38. It typically uses 4 bytes of memory. For example:
```
float a = 3.14;
```
- double: This data type is used to represent double-precision floating-point values, which are decimal numbers with a range of approximately 1.7E-308 to 1.7E+308. It typically uses 8 bytes of memory. For example:
```
double b = 2.71828;
```
3. Character data type:
- char: This data type is used to represent a single character, such as a letter, digit, or symbol. It typically uses 1 byte of memory and can hold values from -128 to 127 or 0 to 255, depending on whether it is signed or unsigned. For example:
```
char c = 'A';
```
4. Boolean data type:
- bool: This data type is used to represent Boolean values, which can only be true or false. In C, the bool data type is defined in the stdbool.h header file. For example:
```
#include <stdbool.h>
bool d = true;
```
In addition to these built-in data types, C also allows the creation of user-defined data types using structures, unions, and enumerations. These data types can be used to group related variables and create more complex data structures.