+ 1

C - Why "a" has the size of an int?

#include <stdio.h> int main() { float a = 10.5; printf("%d %d", sizeof(a), sizeof(10.5)); return 0; }

6th Jan 2020, 12:12 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
3 odpowiedzi
+ 4
Aren't the size of int and float the same.
6th Jan 2020, 12:16 PM
Avinesh
Avinesh - avatar
+ 3
I just want to add that floating point literals that are defined without a suffix like 'f' are by default treated as double values, therefore the sizes of sizeof( a ) and sizeof( 10.5 ) might differ since 'a' is of type float but 10.5 is of type double.
6th Jan 2020, 6:43 PM
Shadow
Shadow - avatar