Largest magnitude?

Hello,

I am working on an assignment and am having problems with one of the questions. The question is : What is the magnitude of the largest value you can place in a bool? a char? an int? a float? a double?

So i made the following program in hopes of finding those answers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <limits.h>
using namespace std;

int main()
{
	int F = INT_MAX;
	char X = CHAR_MAX;
	float Y = FLT_MAX;
	double T = DBL_MAX;



	cout << "F = " << F << endl;
	cout << "X = " << X << endl;
	cout << "Y = " << Y << endl;
	cout << "T = " << T << endl;

	return 0;
}


That code brought about this output:
F = 2147483647
X = ⌂
Y = 3.40282e+038
T = 1.79769e+308
Press any key to continue . . .

Could anyone help me to figure out what I am doing wrong? It would be greatly appreciated.


closed account (Dy7SLyTq)
what do you mean? your not doing anything wrong. int's max for your os is 2147483647. chars max is whatever the ascii value of ⌂ is. floats max is 3.40282 x 10^38 (i think thats how you read that). and double is 1.79769 x 10^308 (once again that might be the wrong way to read it). bool doesnt really have a max. its one value true or false, so its a little different. cout<< sizeof(true) might work
I wasn't sure how to interpret the X value and assumed once I saw that strange symbol that I had made a mistake considering how sloppy the other values look. I now see what you are talking about and would like to thank you for your help.
closed account (Dy7SLyTq)
no problem. we all make mistakes. http://www.asciitable.com/ thats a link to an ascii chart. chars actually hold int values and then the compiler turns that into a character. so if you did char mychar = 99; and then print it you will see it print a c
It looks like correct output? The X = ⌂ - I assume that is the highest value char character. You could find its numerical value by just doing int y = X; . You can get higher values stored if you declare integers or chars as unsigned.
Last edited on
closed account (Dy7SLyTq)
well you can, but you could do cout<< CHAR_MAX i believe.
Topic archived. No new replies allowed.