English

Enlist the basic data types used in C++ with size of data in terms of bytes for each. - Computer Science 1

Advertisements
Advertisements

Question

Enlist the basic data types used in C++ with size of data in terms of bytes for each.

Very Long Answer
Advertisements

Solution

There are three main types of built-in data types used in C++ viz., integral type, void and floating type.

  1. Integral data type: It covers both integers (ints) and characters (chars). An int variable requires 2 bytes to store, while a character variable requires 1 byte. Integer variables are classified into two types: (a) short int and (b) long int. A long integer takes 4 bytes, but a small integer requires only 2.
  2. Void data type: Void data type is used
    1. to specify the return type of a function that does not return any value.
    2. to specify an empty argument list for a function.
    3. to declare generic pointers.
  3. Floating type: Floating type variables are classified into two types: float and double. A float variable requires 4 bytes, while a double variable needs 8 bytes to be stored in memory. Long doubles require 10 bytes to store in memory. The following table displays all basic data kinds, sizes, and ranges:
    Sr. No. Type Bytes Range
    1 char (Signed char) 1 −128 to 127
    2 unsigned char 1 0 to 255
    3 int (short int or signed int) 2 −32768 to 32767
    4 unsigned int 2 0 to 65535
    5 float 4 3.4 × 10−38 to 3.4 × 10−38
    6 double 8 1.7 × 10−308 to 1.7 × 10−308
    7 long double 10 3.4 × 10−4932 to 3.4 × 10−4932
shaalaa.com
  Is there an error in this question or solution?
2024-2025 (March) Official

APPEARS IN

Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×