I'm having trouble reading through a series of *
and &
operators in order to understand two lies of code within a method. The lines are:
int dummy = 1;
if (*(char*)&dummy) { //Do stuff
}
As best I can determine:
dummy
is allocated on the stack and its value is set to1
&dummy
returns the memory location being used bydummy
(i.e. where the1
is)(char*)&dummy
casts&dummy
into a pointer to a char, instead of a pointer to an int*(char*)&dummy
dereferences(char*)&dummy
, returning whatever char has a numeric value of1
This seems like an awfully confusing way to say:
if (1){//Do stuuf }
Am I understanding these lines correctly? If so, why would someone do this (other than to confuse me)?