c - Is this code undefined behaviour? -
i have variable i:
int i; if(b){ i=1; } else{ i=-1; } is i undefined behavior because of int i; exists? or should int i=0 first?
absolutely fine.
you initialising i on program control paths, , not reading value until initialisation complete.
i prefer using ternary operator in such instances.
int = b ? 1 : -1;
as that's less vulnerable accidental reference uninitialised i.
Comments
Post a Comment