Header Ads

Header ADS

DATA TYPE IN C++

 MINI WORLD 

DATA TYPE :

Data types define the type of data a variable can hold, for example an integer variable can hold integer data, a character type variable can hold character data etc. Data types in C++ are categorised in three groups: Built-in, user-defined and Derived.


When we write a program in any language, we need to use various variables like boolean, integer, floating, double, character and the like to store various information. Variables are nothing but reserved memory locations to store values. This means that when we create a variable we reserve some space in memory. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.


DATA TYPES KEYWORDS WHICH USED IN C++ 


TYPE

KEYWORD

Boolean

bool

Integer

int

Floating

float

Double

double

Character

char

String

string

Valueless / Empty

void

Long

long

Short

short

Wide Character

wchar_t

Enumeration

enum

Signed

signed

Unsigned

unsigned















Data Type Wise Memory Size And Range Of Values



TYPE

MEMORY SIZE (BYTE)

RANGE OF VALUES

bool

1 byte

True OR False

char

1 byte

-128 To 127 OR 0 To 255

unsigned char

1 byte

0 To 255

signed char

1 byte

-128 To 127

void

1 byte











short

2 bytes

-32768 To 32767

unsigned short

2 bytes

0 To 65535

short int

2 bytes

-32768 To 32767

unsigned short int

2 bytes

0 To 65535

signed short int

2 bytes

-32768 To 32767

wchar_t

2 bytes

0 To 65535










unsigned

4 bytes

0 To 4294967295

signed

4 bytes

-2147483648 To 2147483647

int

4 bytes

-2147483648 To 2147483647

unsigned int

4 bytes

0 To 4294967295

signed int

4 bytes

-2147483648 To 2147483647

long

4 bytes


long int

4 bytes

-2147483648 To 2147483647

unsigned long int

4 bytes

0 To 4294967295

signed ling int

4 bytes

-2147483648 To 2147483647

float

4 bytes

3.4E +/- 38 (7 digits)










long long

8 bytes

-9223372036854775808 To 9223372036854775807

unsigned long long

8 bytes

0 To 18446744073709551615

signed long long

8 bytes

-9223372036854775808 To 9223372036854775807

long long int

8 bytes

-9223372036854775808 To 9223372036854775807

unsigned long long int

8 bytes

0 To 18446744073709551615

signed long long int

8 bytes

-9223372036854775808 To 9223372036854775807

double

8 bytes

1.7E +/- 308 (15 digits)










long double

12 bytes

Same As Double










enum

varies none








































Data Type Memory Size Code In C++ And Output


#include <iostream>

using namespace std;


int main ()

{

   cout << "THE SIZE OF bool : " << sizeof(bool) << endl;

   cout << "THE SIZE OF char : " << sizeof(char) << endl;

   cout << "THE SIZE OF unsigned char : " << sizeof(unsigned char) << endl;

   cout << "THE SIZE OF signed char : " << sizeof(signed char) << endl;

   cout << "THE SIZE OF void : " << sizeof(void) << endl;


    cout << "THE SIZE OF short : " << sizeof(short) << endl;

    cout << "THE SIZE OF unsigned short : " << sizeof(unsigned short) << endl;

    cout << "THE SIZE OF short int : " << sizeof(short int) << endl;

    cout << "THE SIZE OF unsigned short int : " << sizeof(unsigned short int) << endl;

    cout << "THE SIZE OF signed short int : " << sizeof(signed short int) << endl;

    cout << "THE SIZE OF wchar_t : " << sizeof(wchar_t) << endl;


    cout << "THE SIZE OF unsigned : " << sizeof(unsigned) << endl;

    cout << "THE SIZE OF signed : " << sizeof(signed) << endl;

    cout << "THE SIZE OF int : " << sizeof(int) << endl;

    cout << "THE SIZE OF unsigned int : " << sizeof(unsigned int) << endl;

    cout << "THE SIZE OF signed int : " << sizeof(signed int) << endl;

    cout << "THE SIZE OF long : " << sizeof(long) << endl;

    cout << "THE SIZE OF long int : " << sizeof(long int) << endl;

    cout << "THE SIZE OF unsigned long int : " << sizeof(unsigned long int) << endl;

    cout << "THE SIZE OF signed long int : " << sizeof(signed long int) << endl;

    cout << "THE SIZE OF float : " << sizeof(float) << endl;


    cout << "THE SIZE OF long long : " << sizeof(long long) << endl;

    cout << "THE SIZE OF unsigned long long : " << sizeof(unsigned long long) << endl;

    cout << "THE SIZE OF signed long long : " << sizeof(signed long long) << endl;

    cout << "THE SIZE OF long long int : " << sizeof(long long int) << endl;

    cout << "THE SIZE OF unsigned long long int : " << sizeof(unsigned long long int) << endl;

    cout << "THE SIZE OF signed long long int : " << sizeof(signed long long int) << endl;

    cout << "THE SIZE OF double : " << sizeof(double) << endl;


    cout << "THE SIZE OF long double : " << sizeof(long double) << endl;


    return 0;

}


OUTPUT ::: 


No comments

Powered by Blogger.