I have below C code in which I have applied a not operator on a long double variable:
#include <stdio.h>
int main()
{
long double a;
signed char b;
int arr[sizeof(!a+b)];
printf("\n%d",sizeof(arr));
return 0;
}
This code outputs 16. I have problem in understanding what happenes when we apply not operator on long double, as we have done with a.
Please help me to understand whats happeneing with this code.
Thank You!
From the C Standard (6.5.3.3 Unary arithmetic operators)
So in this expression
the sub-expression
!ahas the typeint.There are used the integer promotions of the operand
bto the typeintin the expression!a + bbecause the rank of the typesigned charis less than the rank of the typeintand the typeintcan represent all values of the typesigned char.From the C Standard (6.3.1.1 Boolean, characters, and integers)
So the full expression is equivalent to
If the
sizeof( int )is equal to4then you have an array declared likeIts size is equal to
16that is to4 * sizeof( int ).