+ 5
Can a variable name be used for two different types?
Can x be defined by double x; and later by int x; such as in a switch? I am thinking about if you made a calculator, you would not be able to use doubles as inputs if you are going to use the % operator, so you would have to declare them as ints. Could you declare them as doubles then ints, or would (I would think) it cause an error?
2 ответов
+ 1
You can not redeclare a type because when you declared int, it reserved 2 bytes in ram, but double takes 4 bytes, so you will need two more bytes, which could be already taken by other variable at that moment.
+ 1
its called overloading name could be same but input parameters and return type must be different