Datatypes in C - Printable Version +- QP School (https://qomplainerzschool.lima-city.de) +-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3) +--- Forum: C 18 Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=32) +--- Thread: Datatypes in C (/showthread.php?tid=5134) |
Datatypes in C - Qomplainerz - 07-26-2023 In C programming, data types are used to define the type and size of data that a variable can hold. Each data type has specific characteristics, and choosing the appropriate data type is essential for efficient memory usage and accurate representation of data. Here is detailed information about all data types in C: Basic Data Types: a. char: - Size: 1 byte - Range: -128 to 127 or 0 to 255 (depending on whether it's a signed or unsigned char) - Description: It is used to store single characters or small integers. b. int: - Size: 4 bytes (on most modern systems, though it can vary) - Range: -2,147,483,648 to 2,147,483,647 - Description: It is used to store whole numbers. c. float: - Size: 4 bytes - Range: ±1.2E-38 to ±3.4E+38 - Description: It is used to store floating-point numbers (numbers with decimal points). d. double: - Size: 8 bytes - Range: ±2.2E-308 to ±1.8E+308 - Description: It is used to store double-precision floating-point numbers. e. void: - Size: N/A (size depends on the system) - Range: N/A (no range; used to indicate an empty or generic type) - Description: It is used as a placeholder for data types and as a return type for functions that do not return any value. Modifiers: a. short: - Size: 2 bytes - Range: -32,768 to 32,767 - Description: It is used to reduce the storage size for integer variables. b. long: - Size: 4 bytes (on most modern systems, though it can vary) - Range: -2,147,483,648 to 2,147,483,647 - Description: It is used to increase the storage size for integer variables. c. signed: - Description: It is used to indicate that the variable can hold both positive and negative values. It is the default for char and int. d. unsigned: - Description: It is used to indicate that the variable can hold only positive values. It is the default for unsigned int. Derived Data Types: a. Arrays: - Description: Arrays are collections of elements of the same data type stored in contiguous memory locations. The size of the array is fixed during declaration. b. Pointers: - Description: Pointers are variables that store memory addresses. They point to the location of other variables in memory. c. Structures: - Description: Structures allow you to group different data types together under a single name. Each member within a structure can have its own data type. d. Unions: - Description: Unions are similar to structures but use the same memory location for all their members. Only one member can be active at a time. e. Enums: - Description: Enums are used to define a set of named integer constants. Each enum constant represents an integer value. Typedef: Description: Typedef allows you to create custom data type names (aliases) for existing data types. It enhances code readability and maintainability. Size_t: Description: size_t is an unsigned data type used to represent the size of objects in memory. It is often used with malloc() and sizeof() functions. Bool (Introduced in C99): Size: 1 byte (C99 standard) Range: 0 to 1 Description: bool is used to represent Boolean values true (1) and false (0). It requires the stdbool.h header. wchar_t (Wide Characters): Size: 2 or 4 bytes (depending on the system) Range: 0 to 65,535 (for 2 bytes) or 0 to 4,294,967,295 (for 4 bytes) Description: wchar_t is used to represent wide characters, which can be used to support multiple character sets. It's important to choose the appropriate data type based on the range and precision required for the data being stored. Understanding data types is fundamental to writing efficient and correct C programs. |