Datatype in c++

Datatype in c++

Data type in c++

Data type in C++

The Data type in c++ are divided into 4 types:-

      primitive:             bool, char, int, float, double,

empty:                  void

    derived:                array, pointer, reference

   user-defined:      enum, typedef, struct, union, and class

some basic or primitive data type with an example:-

bool:-

Boolean can represent true or false.

Any positive or any negative value is true except ‘0’.

Every character is true except ‘/0’ (null) character.

Every time string constant is true for Boolean.

Boolean size is 1 byte because the bit is not accessible. To represent bool 7 bit are wastage.

Example

#include"iostream"

using namespace std;

main()

{

        bool a=10;

        bool b=0;

        bool c=" ";

        bool d='/0';

        bool e='A';

        bool f=1.2;




                cout<<a<<b<<c<<d<<e<<f<<\n;

}

Output:-

1 0  1  0  1  1

Character:-

Char does not store a string constant. Char is an integer constant.

It can not store string type. It can store an int, float, double constant.

Char data type support two modifiers such as signed and unsigned.

Char data type support 2 modifiers such as signed and unsigned.

Example:-

#include"iostream"

using namespace std;

main()

{

        char sec;

        sec="abcdef";

        cout<<sec<<endl;

}

Output:- f

Integer:-

Integer is the combination of 4 char.

All the modifiers are allowed in the integer.

Integer is 4 byte.

 Example:-

#include <iostream>

using namespace std;




int main()

{

    int x = 2, y = 3, temp;




    cout << "Before swapping." << endl;

    cout << "x = " << x << ", y = " << y << endl;




    temp = x;

    x = y;

    x = temp;




    cout << "\nAfter swapping." << endl;

    cout << "x = " << x << ", y = " << y << endl;




    return 0;

}

Output:-

Before swapping 2 3

After swapping     3 2

Float:-

Float is 4byte long.

Float does not support any modifiers.

Example:-

#include"iostream"

using namespace std;

main()

{

     cout << "Size of float is " << sizeof(float) << endl;

}

Output:-

Size of float is 4 byte

 

Double:-

Double is 8 byte long.

Signed, unsigned, shot modifier is not allowed for double.

Example:-

#include"iostream"

using namespace std;

main()

{

                cout << "Size of double is " << sizeof(double) << endl;

}

Output:-

Size of double is 8 byte


 

What are the modifiers in C++?

signed, unsigned, short, long, long long.

 

What are the qualifiers in C++?

const, volatile, mutable

 

basicittopic

basicittopic

A Computer Science Study for IT students and people of IT community