+ 1
what is the size of a if a=10
my sir told that the answer is 2 but the acutal output i got is 4 https://code.sololearn.com/cjO0z6ZBjCs1/?ref=app
3 Answers
+ 12
it's an compiler dependent code, it depends on how compiler will treat the "int" some give size of "int" 4 and some gives 2
+ 7
#include <stdio.h>
main()
{
printf("size of int = %d\n",sizeof(int));
printf("size of short int = %d\n",sizeof(short int));
printf("size of long int = %d\n",sizeof(long int));
printf("size of signed int = %d\n",sizeof(signed int));
printf("size of unsigned int = %d\n",sizeof(unsigned int));
printf("size of float = %d\n",sizeof(float));
printf("size of double = %d\n",sizeof(double));
printf("size of char = %d\n",sizeof(char));
}
// Output :
size of int = 4
size of short int = 2
size of long int = 8
size of signed int = 4
size of unsigned int = 4
size of float = 4
size of double = 8
size of char = 1
+ 1
In fact, you only calculate the size of int, not the size of the whole. Int at Win32 occupy 4 Byte.