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; }

1/6/2020 12:12:12 PM

Paolo De Nictolis

3 Answers

New Answer


sizeof(int) and sizeof float can be same on a particular platform, though it need not be always true.


Aren't the size of int and float the same.


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.