+ 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 ?
5 Antworten
+ 1
I also did the same and it worked!
+ 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
0
Could you please provide an example.Just for clarity
0
I don't have such... I just read in sample test paper that we cannot deduce type as short from auto expression...
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