While typing a program as a high level programmer, n = 0;
looks more efficient and clean.
But is n = 0;
really more efficient than if (n != 0) n = 0;
?
when
n
is more likely to be0
.when
n
is less likely to be0
.when
n
is absolutely uncertainty.
Language: C (C90)
Compiler: Borland's Turbo C++
Minimal reproducible code
void scanf();
void main()
{
int n; // 2 bytes
n=0; // Expression 1
scanf("%d",&n); // Absolutely uncertain
if(n!=0) n=0; // Expression 2
}
Note: I have mentioned the above code only for your reference. Please don't go with it's flow.
If your not comfortable with the above language/standard/compiler, then please feel free to explain the above 3 cases in your preferred language/standard/compiler.