What is Data Type?
In computer programming, a data type is the classification of data according to its representation and processing in a computer system. A programmer will generally specify which data type to use for every variable declared in a program, though some languages automatically assign certain types based on the context. Data types can be classified as either primitive or composite.
Primitive data types are those that have been defined by the language’s designers (for example, integers and floating-point numbers), while composite data types are those whose definition was created by programmers (for example, records and arrays). Different languages support different sets of primitive datatypes; C++ supports nine such data types: int, long int, double, float, char, bool, and void.
The range of values that a data type can store is called its domain. The domain of an integer data type, for example, is the set of all whole numbers between -2147483648 and 2147483647. The domain of a float data type is the set of all numbers between approximately -3.4 * 1038 and 3.4 * 1038, with a precision of about six decimal digits. Characters are typically stored as unsigned bytes with a range from 0 to 255 (256 possible characters).
Some languages also allow programmers to define their own custom data types. For example, in C++ you can create a new datatype by declaring a new data type name, specifying the number of bytes it will occupy in memory, and defining the operations that can be performed on it. You could create a new data type called “person” that would store an employee’s name, Social Security number, and salary, for example.
There are a few basic rules that you need to remember when working with data types:
1. Every variable should have a data type specified for it.
2. The range of values that a data type can store is called its domain.
3. The domain of an integer data type is the set of all whole numbers between -2147483648 and 2147483647.
4. The domain of a float data type is the set of all numbers between approximately -3.4 * 1038 and 3.4 * 1038, with a precision of about six decimal digits.
5. Characters are typically stored as unsigned bytes with a range from 0 to 255 (256 possible characters).
6. You can create your own custom data types in some languages.
7. When working with data types, remember the basic rules: every variable should have a data type specified for it, the domain of a data type is its range of values, and be aware of the precision of different data types.
8. The size of a data type refers to how many bits it occupies in memory. For example, an integer may be 32 bits wide, while a float maybe 32 or 64 bits wide.