+ 1

Why can't type be deduced to short from Auto

Hi I read a statement that compiler can't deduce the type of expression to short from auto declaration.. It can be converted to double float etc but not short... Why is it so ? Any specific reason for same ?

1st Jun 2020, 10:03 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
5 Respostas
+ 1
I also did the same and it worked!
1st Jun 2020, 5:22 PM
Anthony Maina
Anthony Maina - avatar
+ 1
But I think what people in forums mean by asking this question is why the compiler deduces num in auto num=12 to be int instead of short since it seems reasonable to store it in a short to conserve space. And to be honest I also don't know the answer.Maybe that's just how the language is implemented
1st Jun 2020, 5:28 PM
Anthony Maina
Anthony Maina - avatar
0
Could you please provide an example.Just for clarity
1st Jun 2020, 1:07 PM
Anthony Maina
Anthony Maina - avatar
0
I don't have such... I just read in sample test paper that we cannot deduce type as short from auto expression...
1st Jun 2020, 4:11 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Tried to typecast short on auto.. I thought it might not give type property but it says s for short as required: https://code.sololearn.com/coa5Px71UiPD/?ref=app
1st Jun 2020, 5:14 PM
Ketan Lalcheta
Ketan Lalcheta - avatar