0

Question about C

Why do we do : Average =(float) a+b; Why not this : Float average = a+b ???

30th Oct 2020, 4:24 PM
NotMicah
5 odpowiedzi
+ 2
Average is a new variable and a is another variable.if you declare Average as float datatype a also have to be of float datatype so we do conversion .
30th Oct 2020, 4:34 PM
HBhZ_C
HBhZ_C - avatar
+ 1
Ohhhh so you mean , a and b needs to be float not string or char ?
30th Oct 2020, 4:36 PM
NotMicah
0
All three variables must be in the some datatype .Here you do an addition so you can not do addition with different variables datatype so you can not added a float to string or float to integer You will store the addition result as float not as string or integer this will produce a type error
30th Oct 2020, 4:42 PM
HBhZ_C
HBhZ_C - avatar