+ 1
Explain me how plz
int x=10; int sum=0; while(x--); { sum+=x--; printf("%d",sum); output is -1...how plz tell me
7 Answers
+ 7
Notice the semicolon after the while loop. It subtracts x until -1.
+ 6
@corejava When it reaches zero, It subtracts it by one then it stops.
+ 3
The sum +=x--; happens outside the while loop.
As qwerty said, there is a semicolon after the while statement. The question is tricky trying to make you think the sum variable is in the while loop.
+ 3
Nice breakdown Gordie.
+ 2
y until -1 I couldn't get it....if while has zero only na the loop fails
+ 2
wen it while gets 0 it will not enter the loop right
if it enters only sum will process..coz sum is with in while