C++ Program to Find Size of int, float, double and char in Your System
In Turbo C++, you can use the sizeof operator to find the size (in bytes) of various data types like int, float, double, and char. Here’s a simple C++ program to display the sizes of these data types:
#include <iostream.h>
#include <conio.h>
void main() {
clrscr(); // Clear the screen (specific to Turbo C++)
cout << "Size of int: " << sizeof(int) << " bytes" << endl;
cout << "Size of float: " << sizeof(float) << " bytes" << endl;
cout << "Size of double: " << sizeof(double) << " bytes" << endl;
cout << "Size of char: " << sizeof(char) << " byte" << endl;
getch(); // Wait for user input (specific to Turbo C++)
}
In this program, I’ve used clrscr() to clear the console screen and getch() to wait for a character input before closing the program. Both of these functions are specific to Turbo C++ and may not work in other environments.
To compile and run this program:
- Open Turbo C++.
- Create a new file and copy-paste the above code.
- Compile the code.
- Run the program.
You should see the sizes of the respective data types in bytes on the screen.
