0
why answer is 16?
#include <stdio.h> void main() { // Write C code here long double a; signed char b; int arr[sizeof(!a+b)]; printf("%d",sizeof(arr)); } // answer is 16
5 odpowiedzi
+ 1
If you pass !a to sizeof(), everything I explained earlier still holds, since the type of !a is int. However, if you construct the array with
sizeof( a + b )
elements, then the output changes because
a + b
is of type long double, not int, and sizeof( long double ) is 16 on SoloLearn's system. From then on, it applies again that for an array of 16 integers, each occupying 4 byte, the size of the total array would turn out 64.
+ 6
The logical NOT operator has type int, therefore the expression
!a + b
is an int as well, which typically has a size of 4 byte on 64-bit systems.
As a consequence, "arr" is an array of four integers, making its total size 16 byte, although the exact output depends on the size of int on the system the code is compiled on.
0
Shadow Thank you so much
0
But I am a little confused..how is arr consist of 4 intergers. Shadow....in line 3 after main function if I pass !a the ans remains 16 but if I change the parameter to a+b the ans is 64.
0
Shadow I get it now🤗.thanks