+3 votes
in Class 11 by kratos

Explain the basic data types in details.

1 Answer

+6 votes
by kratos
 
Best answer

In computer programming, information is stored in a computer memory with different data types. We must know what is to be stored in a computer memory, whether it is a simple number, a letter or a very large number.

Basic Data types in C++

1. character:

C++ offers a predefined data type that is one byte in size, which can hold exactly one character such as ‘a’ or ‘A’. To declare a variable of type char, we have char ch;

Suppose we want to store a character value ‘a’, in a char data type eh, it is enclosed within a single quote. ch = ‘a’;

Only a single character can be stored in a variable of type char.

2. integer: On most machines, the size of int type is 2 bytes. C++ defines this type as consisting of the values ranging from -32768 to 32767. This range is for the small integer. If a long integer is needed, the type long or long int can be used. The range of long int is too big that is from -2147483648 to 2147483647, which occupies 4 bytes in memory.

3. float: C++ defines the data type float, as representing numbers that have a fractional part. For example, 12.55 as opposed to integers which have no fractional part. Floating-point variables can either be small or large. A variable with type float occupies 4 bytes in size and can hold numbers from 10-308 to 10+308 with about 15 digits of precision. There is a long double, also available, that can hold numbers from 10-4932 to 10+4932 .

4. Bool: It is an additional data type for representing a Boolean value. A variable associated with a bool data type may be assigned an integer value 1 to the literal true and a value 0 to the literal false.

...