Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does sizeof(!5.6) give an output 2?

Tags:

c

sizeof

Even if we declare float a=5.6 then printf("%d",sizeof(!a)) outputs 2. Why does it output size of integer?

like image 721
Heisenberg Avatar asked Dec 08 '22 14:12

Heisenberg


2 Answers

The ! operator returns an integral type, likely int. sizeof(int) == 2 on your architecture, apparently.

like image 107
PfhorSlayer Avatar answered Dec 22 '22 18:12

PfhorSlayer


The ! operator doesn't return the type of the operand. If you perform a NOT on a float, you're not going to get a float back. You are going to get an int with the logically opposite value of the initial float.

like image 20
Theodoros Chatzigiannakis Avatar answered Dec 22 '22 19:12

Theodoros Chatzigiannakis