Doubt in a question... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Doubt in a question...

I recently encountered this question in a challenge: What value can 'int' have? : 0) whole numbers 1) text 2) any number 3) characters Now, the creator marked the answer as whole numbers. But by default, integers are signed, and so have the default range = -32768 to 32767... And according to mathematics, whole numbers are the set: W = +Z //Only positive (unsigned) integers... or W = N + {0}; //Natural Numbers, and a zero... Then how can the answer be whole numbers?

19th Jun 2017, 3:41 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
7 Answers
+ 11
Int variables can store up to max lim (2^31-1) and min lim -(2^31-1). While INT_MAX +1 is a whole number and also beyond the boundaries of what int variables can store, it should only be natural to operate according to the confines of limits. Whole numbers are numbers containing no fractions or decimal points, this is what in integer means. Characters are not integers. You can assign char values to int variables, but they will be converted to their ASCII int value counterparts, i.e. int variables cannot store characters. Same goes to other answers apart from whole numbers. When you go for any number, you include 6.33, 4/3, π, and other floating-point values which will be automatically 'floored' to whole numbers. tl;dr - While char and float/double values can be assigned to int variables, int variables cannot store them. They will be converted to whole numbers. While the question 'what value can 'int' have' may not be worded the best way, the most logical and mathematically appropriate answer would be whole numbers.
19th Jun 2017, 3:58 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
Well, it wasn't the most appropriate answer. It was the correct answer. When we are asking 'what can int store', we are really asking 'what is a subset of integers'. Whole numbers do not represent all integers, but all whole numbers are integers and hence int variables can store all whole numbers (up to INT_MAX) without fail. Let's take a look at 'Any number'. Is 'Any number' a subset of integers? No, it is a superset of integers. I.e. There are some elements of 'Any number' which cannot be stored by int variables. Text and characters are out of the question. So when we rephrase the question by including the answer: Can 'int' store whole numbers? Yes - True for all cases and instances of whole numbers. Surely, int variables can store much more than just whole numbers. If the question was asking 'what is 'int'', whole numbers would be wrong.
19th Jun 2017, 4:23 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
Thank you too, it made me think.
19th Jun 2017, 4:33 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Hmm, whole numbers is a subset of int after all. I guess I got it wrong... Thank You!
19th Jun 2017, 4:10 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 5
Thank You very much! ^_^
19th Jun 2017, 4:24 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
I tried any number, but the creator may have assumed this option to contain all numbers in the real number set, or R... So, shouldn't the creator specify things a little? I mean how can it be whole numbers?
19th Jun 2017, 3:44 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
0
You're welcome
19th Jun 2017, 5:04 AM
Ash
Ash - avatar