While studying C I faced something that is completely confusing my mind.
The expression is:
exp(V*log(i))?i%2?s:s--:s++;
If ternary operator is Question?Positive:Negative; I thought it was something like:
if(pow(i,V)==1&&(i%2)==0)
s--;
else
s++;
However, the s does not enter in the question, should I ask what does the first expression mean?
The program worked perfectly, but I could not understand why.
The original program is:
main(){
#define V 1
int a, s=0, i;
for(i=1000;i>=0;i--)
exp(V*log(i))?i%2?s:s--:s++;
exp(V*log(i))?printf("%d\t%d\t",-s,i):printf("%d\t%d\t", s,-i);
getch();
}
If exp(Vlog(i)) is true then test is it odd i%2==1 if it is return s if even return s-- if exp(Vlog(i)) is false return s++ If you write it like this than is easier to see: