+ 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

25th Aug 2018, 4:28 PM
sasidhar kondumahanthy
sasidhar kondumahanthy - avatar
3 odpowiedzi
+ 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
25th Aug 2018, 5:01 PM
GAWEN STEASY
GAWEN STEASY - avatar
+ 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
25th Aug 2018, 8:38 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
In fact, you only calculate the size of int, not the size of the whole. Int at Win32 occupy 4 Byte.
26th Aug 2018, 3:31 AM
Heju Tian
Heju Tian - avatar