Below snippets in C check if foo() and bar() returns nonzero value and execute something() if needed. Are they equivalent? Why?
// first version
if (foo() && bar()) {
something();
}
// second version
if (bar() && foo()) {
something();
}
// third version
if (foo()) {
if (bar()) {
something();
}
}
they're the same
ReplyDeleteNo, they aren't ;-)
DeleteWith the second version, if bar() is false then foo() won't be checked.
ReplyDelete