Computer Science, asked by architchimania1202, 9 months ago

what will be the value of x if a=6, b=8? x = a++ + --a + b++ + a++ + a +--b

Answers

Answered by dineshminnu14751
0

Answer:

12

Explanation:

20-8.. hy aahy uza answer

Answered by mad210203
1

Given:

The values of a and b are a = 6 and b = 8.

To find:

We need to find the value of x, where x = a++ \ \ + \ \  --a  \ \ + \ \  b++  \ \ +  \ \ a++  \ \ +  \ \ a + \ \ --b.

Solution:

Before solving this question, we need to revise some concepts related to increment and decrement.

  • Pre - increment (++p): In this type of increment, before assigning the value to the variable, the value is incremented by one.
  • Post - increment (p++): In this type of increment, after assigning the value to the variable, the value is incremented by one.

  • Pre - decrement (--p): In this type of decrement, before assigning the value to the variable, the value is decremented by one.
  • Post - decrement (p--): In this type of decrement, after assigning the value to the variable, the value is decremented by one.

Now, consider the given expression, let that equation be (i),

x = a++ \ \ + \ \  --a  \ \ + \ \  b++  \ \ +  \ \ a++  \ \ +  \ \ a + \ \ --b....... (i)

We will solve the above equation part by part.

1. Consider a++,

  • This is post - increment case.
  • So, assign the value to the variable and then increment the a by one.
  • So, a++=6.
  • Now the value of a is 6+1=7.

2. Now consider --a,

  • This is pre - decrement case.
  • So, before assigning the value to the variable, the value of a is decremented by one.
  • Now the value of a is 7-1=6.
  • So, --a=6.

3. Consider b++,

  • This is post - increment case.
  • So, assign the value to the variable and then increment the b by one.
  • So, b++=8.
  • Now the value of b is 8+1=9.

4. Consider a++,

  • This is post - increment case.
  • So, assign the value to the variable and then increment the a by one.
  • So, a++=6.
  • Now the value of a is 6+1=7.

5. Consider a,

  • The value of a is 7.

6. Now consider --b,

  • This is pre - decrement case.
  • So, before assigning the value to the variable, the value of b is decremented by one.
  • Now the value of b is 9-1=8.
  • So, --b=8.

Now, substitute all these values in equation (i).

\Rightarrow x = a++ \ \ + \ \  --a  \ \ + \ \  b++  \ \ +  \ \ a++  \ \ +  \ \ a + \ \ --b

\Rightarrow x = 6 \ \ + \ \ 6  \ \ + \ \  8  \ \ +  \ \ 6  \ \ +  \ \ 7 + \ \ 8

\Rightarrow x =41

Therefore, the value x of is 41.

Similar questions