0

Int vs Var?

I just looked at a test on Solo Learn. it asked me to finish the code by filling in the blanks, so I did. it said I was wrong by typing "var" instead of "int" for a code with math? technically, I should be able to declare the whole number a variable.. right?

20th Nov 2017, 1:55 PM
Howard Eugene Patrick Jr
Howard Eugene Patrick Jr - avatar
3 Respostas
+ 4
@kinshuk i think in use we can only store -(2^31) to ((2^31)-1)as one bit will be used as most significant bit for determining wether the number is positive or not.
20th Nov 2017, 3:07 PM
shobhit
shobhit - avatar
+ 3
var isn't available in c++. Try using auto. You see, all things you declare like this: int a, b, var; Are variables. You can store any value that corresponds to the type specified during creation. For eg, a is an int. You may not store 2.2 (Real Number) in this variable. But you may store any integer in the range -(2^32) to 2^32-1 in this variable.
20th Nov 2017, 2:00 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
@Shobhit Yes the limits are -2^31 to 2^31-1, but actually integers use two complement form to store negative numbers.
20th Nov 2017, 3:10 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar