Question: Compile and run the code below as sizes.c Based on the results of this, draw a labelled diagram (bar graph) showing the relative sizes of

Compile and run the code below as sizes.c

Based on the results of this, draw a labelled diagram (bar graph) showing the relative sizes of an int, a char a float and a double in terms of how much memory they occupy.

#include

#include

int main()

{

int size, max, min;

/*******************************

* Calculate the size of an int

*******************************/

size = sizeof(int) * 8;

printf("The size of an int variable is %d bits. ", size);

/* maximum value is 2^(n-1)-1 where n is the size in bits. */

max = pow(2, (size-1)) - 1;

/* minimum value is -2^(n-1) where n is the size in bits */

min = 0 - pow(2, (size-1));

printf("The maximum value that can be stored is %d and the minimum is %d ", max, min);

/*******************************

* Calculate the size of a long int

*******************************/

size = sizeof(long int) * 8;

printf("The size of a long int variable is %d bits. ", size);

/* maximum value is 2^(n-1)-1 where n is the size in bits. */

max = pow(2, (size-1)) - 1;

/* minimum value is -2^(n-1) where n is the size in bits */

min = 0 - pow(2, (size-1));

printf("The maximum value that can be stored is %d and the minimum is %d ", max, min);

/*******************************

* Calculate the size of an char

*******************************/

size = sizeof(char) * 8;

printf("The size of an char variable is %d bits. ", size);

/* maximum value is 2^(n-1)-1 where n is the size in bits. */

max = pow(2, (size-1)) - 1;

/* minimum value is -2^(n-1) where n is the size in bits */

min = 0 - pow(2, (size-1));

printf("The maximum value that can be stored is %d and the minimum is %d ", max, min);

/*******************************

* Calculate the size of an float

*******************************/

size = sizeof(float) * 8;

printf("The size of a float variable is %d bits. ", size);

/*******************************

* Calculate the size of an double

*******************************/

size = sizeof(double) * 8;

printf("The size of a double variable is %d bits. ", size);

return(0);

}

thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!