---
title: "Final values of a, b and c"
subject: "Computer Programming"
chapter: 3
key: "semester_1/computer_programming:final-values-abc"
source: https://www.bctengineer.com/q/semester_1/computer_programming/final-values-abc
site: BCT Engineering
---

# Final values of a, b and c

Computer Programming · Chapter 3: Introduction to ‘C’ programming

- Asked in: 2070 Chaitra, 4 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/final-values-abc
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-3

## Question

Find out final value of a, b and c where following expressions are executed sequentially.
```
int a = 2, b = 3, c;
a = (b++) + (++b) + a;
c = a > b ? a:b;
b = (a++) + (b--) +a;
c = c++*b--;
```

## Short answer

a=11, b=25, c=260. a=(b++)+(++b)+a gives 10; c=10; b=(a++)+(b--)+a gives 26; c=c++*b-- gives 260 and b becomes 25. Note: multiple side effects on same variable yield technically undefined behavior.

## Answer

Initially a = 2, b = 3.

**Statement 1:** `a = (b++) + (++b) + a;`
- `b++` gives 3 (b becomes 4); `++b` makes b = 5 and gives 5.
- a = 3 + 5 + 2 = 10, b = 5.

**Statement 2:** `c = a > b ? a : b;` Since 10 > 5, c = 10.

**Statement 3:** `b = (a++) + (b--) + a;`
- `a++` gives 10 (a becomes 11); `b--` gives 5 (b becomes 4); the last `a` is 11.
- b = 10 + 5 + 11 = 26.

**Statement 4:** `c = c++ * b--;`
- `c++` gives 10 and `b--` gives 26, so c = 10 * 26 = 260 (the assignment overwrites the increment of c), and b-- makes b = 25.

Values after each statement:

| After statement | a | b | c |
|---|---|---|---|
| 1 | 10 | 5 | not set |
| 2 | 10 | 5 | 10 |
| 3 | 11 | 26 | 10 |
| 4 | 11 | 25 | 260 |

**Final values: a = 11, b = 25, c = 260.**

Note: expressions such as `(b++) + (++b)` and `c = c++ * b--` change the same variable twice without a sequence point, so the C standard leaves the result undefined; compilers warn about it and may give different values. The values above are the usual textbook evaluation, from left to right.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. After c = a > b ? a : b; with a=10, b=5, c is:
   A. 5
   B. 10
   C. 1
   D. 15
   Answer: B. The condition 10 > 5 is true, so c takes a. (Key point: Conditional)

2. The final values after c = c++*b-- are:
   A. a=11, b=25, c=260
   B. a=11, b=26, c=260
   C. a=10, b=25, c=250
   D. a=11, b=25, c=270
   Answer: A. c = 10*26 = 260 and then b-- makes b 25. (Key point: Final values)

## Related in Computer Programming

- [Swap two values using pointers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apointer-swap-function) — Computer Programming, chapter 9

## Related in other subjects

- [State and prove final value theorem](https://www.bctengineer.com/question.md?key=semester_4%2Fapplied_mathematics%3Afinal-value-theorem-prove) — Applied Mathematics, chapter 2, asked 5×
- [z-transform of (1-e^{-at}); final value](https://www.bctengineer.com/question.md?key=semester_4%2Fapplied_mathematics%3Az-transform-1-minus-e-at-final) — Applied Mathematics, chapter 2, asked 2×
- [Final value theorem for Z-transform](https://www.bctengineer.com/question.md?key=semester_3%2Fmathematics_iii%3Afinal-value-theorem-for-z-transform) — Mathematics III, chapter 3
- [Final value theorem of z-transform](https://www.bctengineer.com/question.md?key=semester_6%2Fdigital_control_system%3Afinal-value-theorem) — Digital Control System, chapter 2
