+ 2

C program to find size...can anyone tell me how this program works?

Size of https://code.sololearn.com/c4K8cykTcAx3/?ref=app

6th Jun 2019, 2:54 PM
Abhijeet Pawar
Abhijeet Pawar - avatar
3 Respuestas
+ 6
sizeof returns the memory size of the value you pass to it. unsigned size1 = sizeof(10.2); returns 8, because the number is of type double which is of size 8 (bytes). unsigned size2 = sizeof(010); returns 4 because 010 is an octal number literal, which translates to a normal int which is of size 4. Most interesting is line 3: unsigned size3 = sizeof(ch+d); ch is a char, which is of size 1, but d is a double. When you add two numbers (char is represented as a letter, but internally it is a number) of different types, the smaller type is 'upgraded' first, so the result will be of the larger type, in this case double, so 8 bytes.
6th Jun 2019, 3:15 PM
HonFu
HonFu - avatar
+ 1
An int variable, for example, is typically allocated 4 bytes when declared. We know this by using the sizeof operator: Exam: int x; Printf ("%d" , sizeof (x));
6th Jun 2019, 9:11 PM
‎محمد النزهي‎
‎محمد النزهي‎ - avatar