C++ & Python Program to calculate the size of each data types

Posted in

C++ & Python Program to calculate the size of each data types

Vinay Khatri
Last updated on August 23, 2022

    In this program, we will display a program to calculate the size of each data types with the help of C++ and Python.

    C++ Program Calculate the size of each data types

    #include<iostream.h>
    #include< conio.h>
    #include<stdio.h>
    #include<math.h>
    
    void main()
    {
    clrscr();
    cout<<"The size of integer is: "<<sizeof(1);
    cout<<"\nThe size of float is: "<<sizeof(1.1);
    cout<<"\nThe size of Character is: "<<sizeof('a');
    cout<<"\nThe size of long int is: "<<sizeof(long);
    cout<<"\nThe size of Double is: "<<sizeof(double);
    getch();
    }

    Output:

    The size of integer is: 2
    The size of float is: 8
    The size of character is: 1
    The size of long is: 4
    The size of Double is: 8

    Python Program Calculate the size of each data types

    import sys
    print("The size of integer is:",sys.getsizeof(1))
    print("The size of float is:",sys.getsizeof(1.0))
    print("The size of character is:",sys.getsizeof('a'))
    print("The size of complex is:",sys.getsizeof(1+2j))

    Output

    The size of integer is: 14
    The size of float is: 16
    The size of character is: 26
    The size of complex is: 24

    People are also reading:

    Leave a Comment on this Post

    0 Comments