C++ Examples

WAP in C++ to Find Size of Fundamental data types!

The Program in C++ to Find Size of Fundamental data types is given below:

#include <iostream>
#include <climits> // for INT_MAX and INT_MIN

int main() {
    std::cout << "Size of char : " << sizeof(char) << " bytes" << std::endl;
    std::cout << "Size of int : " << sizeof(int) << " bytes" << std::endl;
    std::cout << "Size of short int : " << sizeof(short int) << " bytes" << std::endl;
    std::cout << "Size of long int : " << sizeof(long int) << " bytes" << std::endl;
    std::cout << "Size of float : " << sizeof(float) << " bytes" << std::endl;
    std::cout << "Size of double : " << sizeof(double) << " bytes" << std::endl;
    std::cout << "Size of wchar_t : " << sizeof(wchar_t) << " bytes" << std::endl;
    return 0;
}

Output:

Size of char : 1 bytes
Size of int : 4 bytes
Size of short int : 2 bytes
Size of long int : 8 bytes
Size of float : 4 bytes
Size of double : 8 bytes
Size of wchar_t : 4 bytes

Pro-Tips💡

This code uses the sizeof() operator to determine the size of the fundamental data types char, int, short int, long int, float, double, and wchar_t.

The sizeof() operator returns the size of the data type in bytes.

The cout function is used to print the size of each data type to the screen, along with the string “bytes” for clarity.

Note that It is also possible to check the range of the fundamental data types with the help of climits library, for example INT_MAX,INT_MIN for int type.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X