Which of the following three if statements are equivalent?
(i) if (aa == bb)
{ if (xx == yy) flag = true; }
else flag = false;
(ii) if (aa == bb)
{ if (xx == yy) flag = true;
else flag = false; }
(iii) if (aa == bb) if (xx == yy) flag = true; else { flag = false; }
Here is my analysis:
i. aa equal bb, xx equal yy (flag = true),
aa not equal bb (flag = false),
aa equal bb, xx not equal yy (flag = unknown)
ii. aa equal bb, xx equal yy (flag is true)
aa not equal bb (flag = unknown)
aa equal bb, xx not equal yy (falg = false)
iii. aa equal bb, xx equal yy (flag is true)
aa not equal bb (flag = unknown)
aa equal bb, xx not equal yy (falg = false)
Therefore ii & iii shd be the ans. Am i rite?
Tks a lot!!!
Tags: