0
Please solve and send me explanation.
When i gave my coding test i got this question and tried all the way i know but can't understand this question. If anyone can solve this then send me its explanation. The question is #include <stdio.h> int main() { int x=2; int y=5; x+=1; y-=x; y++; printf("%d",y); return 0; }
6 odpowiedzi
+ 7
go over it line by line.
write what's the variable's expected value should be after each operation.
x+= 1; // x= 3
y-=x: // y = 5-3 = ?
y++; // y = ?
+ 6
it's not even a question. you can just run the code to get the answer. The purpose is to understand how it is obtained.
int x = 2;
int y = 5;
x+=1 means add 1 to the value of x
x+= 1; // x= 2+1 = 3 (x was 2, now it's 3)
y-=x means subtract x from y
y-=x: // y = 5-3 = 2 (y was 5, now it's 2)
y++ means add 1 to y. it's the same as y+=1
y++; // y = 2 +1 = 3
// so what's the final value of y? 3.
printf("%d", y); //prints 3
+ 5
John Greals ,
having a look to your `codebits` makes me believe that you should be able to understand what your mentioned code is doing and how it does work.
+ 4
As Bob_Li said, go over it line by line - you could/should put a print after every statement and see what's happening.
+ 3
What is your expected output?
If you can explain how to get your expected output, then we can discuss in details how it is correct or wrong.
0
I don't know