100-500 words per explanation and avoid plagiarism.
Explain the following datatypes in your own words without copying it from
anywhere.
a. int
b. float.
c. double.
d. string.
e. Bool.
1. Int – one of the most popular data types. It represents digital implementation of integer (whole) numbers. In C++, it usually consists of 32 bits, so, signed int contains whole numbers from -231 to 231-1.
First bit of a 32-bit sequence is a sign bit. If it is zero, the number is positive, and if one – negative. Other 31 bits represent presence of two in some power. If i-th bit is 1, then 2i is added to number’s value. Overall value is a sum of these powers. But if the number is negative, the value is calculated using two’s complement, which simplifies operations with numbers of different signs.
2. Float – 32-bit data type for representing floating-point numbers in computers. Bits are divided into three parts – sign (1 bit, same as in int), mantissa (23 bits), and exponent (8 bits). The number is represented in an exponential format, so mantissa contains normalized number in a form 0.10101..0, and exponent stands for the power, into which mantissa should be multiplied. It can contain values in range of 10-38 to 1038.
3. Double – 64-bit data type for floating-point numbers (double precision float). It is divided into sign (1 bit), mantissa (52 bits), exponent (11 bits). It can contain values in range of 10-308 to 10308.
4. String – data type for storing sequences of symbols. Though it is a built-in type, it is needed to include a standard library (std::) in order to use strings. Each symbol of a string is a character, which is 8 bits and contains global symbols (codes from 1 to 127) and local (128 to 255 or -128 to -1). Strings can be appended to each other, compared, and other useful things.
5. Bool – data type for representing Boolean values (true/false). Though it is enough to use 1 bit for storing it, variable of that type uses the whole byte. The array of bools uses 1 byte for each element, but std::vector<bool> is optimized to use 1 bit for each element.
Comments
Leave a comment