Write a simple program that uses the sizeof function to di

Write a simple program that uses the \'sizeof () \' function to display the number of bytes in a: (example of use: int shortsize = sizeof (short);//returns the size, in bytes (8bits = 1byte)) Find and display the size of: short int int long int char float double

Solution

*Note if you are using Linux, there are minor differences in code for windows and linux editors. I have mentionined both of them here, pick whichever you prefer.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

1.This is Windows version of the code (i.e.Turbo C++) :

#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

cout<<\"Size Of short int -->\"<<size0f(short int) <<endl;

cout<<\"Size Of int -->\"<<sizeof(int)<<endl;

cout<<\"Size Of long int -->\"<<sizeof(long int)<<endl;

cout<<\"Size Of char -->\"<<sizeof(char)<<endl;

cout<<\"Size Of float -->\"<<sizeof(float)<<endl;

cout<<\"Size Of double -->\"<<sizeof(double)<<endl;

getch();

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

2. This is Linux Version of the code :

#include<iostream>

using namespace std;

int main()

{

cout<<\"Size Of short int -->\"<<size0f(short int) <<endl;

cout<<\"Size Of int -->\"<<sizeof(int)<<endl;

cout<<\"Size Of long int -->\"<<sizeof(long int)<<endl;

cout<<\"Size Of char -->\"<<sizeof(char)<<endl;

cout<<\"Size Of float -->\"<<sizeof(float)<<endl;

cout<<\"Size Of double -->\"<<sizeof(double)<<endl;

return 0;

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 Write a simple program that uses the \'sizeof () \' function to display the number of bytes in a: (example of use: int shortsize = sizeof (short);//returns the
 Write a simple program that uses the \'sizeof () \' function to display the number of bytes in a: (example of use: int shortsize = sizeof (short);//returns the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site