Site icon TestingDocs.com

C++ Intrinsic data types

Overview

C++ intrinsic data types are built into the language. These are also called primitive data types. There are several intrinsic datatypes that developers can declare and use the variables in the C++ programs.

C++ Intrinsic Datatypes

Some of the examples are as follows:

Based on the data type the operating system allocates memory for the variables.

C++ Built-in Datatypes

void no type
bool boolean
char character
int integer
float single-precision floating-point
double double-precision floating-point
wchat_t wide character type

 

The below program displays the sizes of various primitive datatypes onto the console in bytes.

C++ Program

/************************************
* C++ Intrinsic DataTypes
* Filename: datatypes.cpp
* C++ Tutorials - www.TestingDocs.com
**************************************/
#include 
using namespace std;
int main()
{
    cout << "C++ Intrinsic DataTypes" << endl;
    cout << "Size void Datatype  : " << sizeof(void) << " bytes "<<endl;
    cout << "Size bool Datatype  : " << sizeof(bool) << " bytes "<<endl;
    cout << "Size char Datatype  : " << sizeof(char) << " bytes "<<endl;
    cout << "Size int Datatype   : " << sizeof(int) << " bytes "<<endl;
    cout << "Size float Datatype : " << sizeof(float) << " bytes "<<endl;
    cout << "Size double Datatype: " << sizeof(double) << " bytes "<<endl;

    return 0;
} // end main

Output

C++ Intrinsic DataTypes
Size void Datatype : 1 bytes
Size bool Datatype : 1 bytes
Size char Datatype : 1 bytes
Size int Datatype : 4 bytes
Size float Datatype : 4 bytes
Size double Datatype: 8 bytes

 

 

The sizeof() function returns the size of the data type passed to the function. For example, sizeof(char) returns 1. The units of the function are Bytes.

C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Exit mobile version