c - scanf() prevents runtime error when inside conditon block -


why program run correctly

s,x="%d"; main(a,t){ for(scanf(x,&t);t--&&scanf(x,&a);)     s+=(a>0)*a; printf(x,s); } 

and program doesn't , , gives runtime error

s,x="%d"; main(a,t){ for(scanf(x,&t);t--;s+=a*(a>0))     scanf(x,&a); printf(x, s); } 

my second program works if give return 0; @ end.
putting scanf() inside condition block makes work ?

sample input :

4 5 -5 6 -1 

s,x="%d"; main(a,t){ for(scanf(x,&t);t--;s+=a*(a>0))     scanf(x,&a); printf(x, s); } 

this 1 not work due for(scanf(x,&t) ;t--; s+=a*(a>0))

your stop condition t--, going endless loop.


Comments