Computer Science, asked by dorlhysantiago07, 1 year ago

What is the output for code A and B?:


*Code A: var x = 10; y = --x + 1; alert(y);

*Code B: var x = 10; y = x-- + 1; alert(y);


a) 11, 10 b) 10, 10

C) 10, 11 d) 11, 11

Answers

Answered by Anonymous
4
If these are two different conditions then the answer will be:
C)10, 11
Answered by sarahssynergy
0

The output of A and B are option (c)10,11

Explanation:

  1. "--" before the variable is used to decrease variable value by  one before putting the value in the variable.
  2. "--" after the variable is used to decrease variable value by one after putting the value in the variable.
  3. here, in A "--"  is used before the variable that's why the value of x is decreased by one before it is added to one in  y= --x+1        
  4. here, in B "--" is used after the variable  that's why the value of x is decreased by one after it is added to one in  y= x-- +1
  5. hence, value of y in A is 10 and in B is 11

Similar questions