Press ESC to close

C++ Program to Find the Size of int, float and char

Photo by Rodrigo Santos 

A simple C++ program that finds and prints the sizes of int, float, and char data types.

#include <iostream>
using namespace std;
int main() {
    // Find and print the size of an int
    cout << "The size of an int is: " << sizeof(int) << " bytes" << endl;
    // Find and print the size of a float
    cout << "The size of a float is: " << sizeof(float) << " bytes" << endl;
    // Find and print the size of a char
    cout << "The size of a char is: " << sizeof(char) << " bytes" << endl;
    return 0;
}

This program uses the sizeof operator to determine the sizes of int, float, and char types and prints the results. The sizeof operator returns the size in bytes, making it easy to understand the memory requirements of these data types.

Leave a Reply

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