I have a problem here asking me to display the minimum and maximum a variable can store including: Short, Integer, Long and Float. I’m supposed to initilize it with one less than the correct answer, then add 1 to it to prove the variable doesn’t give an error. Example.
short srtMaximum = 32766;
srtMaximum += 1;
System.out.print(”Max value for short is “ + srtMaximum);
I’m supposed to do this for C and Java. Java I did no problem. Short is -32768, 32767 Int is -2,147,483,648, 2,147,483,647 Long -9quintillionL, 9 quintillionL Float was something I can’t remember off the top of my head
But with C is where I’m confused.
Short seems to be the same.
But Long can only hold the same value as an Int?
The documentation says an int can sometimes only be -32768 - 32767?
And I have no idea how to do this project with floats. No matter what value I assign the float to test it, it prints something different in printf
c'slong long? - GBlodgettInteger.MAX_VALUE...? - Dang NguyenInteger.MAX_VALUEandInteger.MIN_VALUE. If memory serves, in C, only a minimum size for each type is specified hence there is no direct comparison. - davesizeof(char) <= sizeof(short),sizeof(short) <= sizeof(int),sizeof(int) <= sizeof(long), andsizeof(long) <= sizeof(long long). The C specification says thatsizeof(char)will always be equal to1, and thatlong long` is at least a 64-bit type. You can find out the limits for the current implementation/target by using<stdint.h>and<limits.h>- Some programmer dude