Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions