What will this code output?
```c
int a = 5;
a = 10;
printf("%d", a);
```
A
5 B
10 C
0 D
Error
Analysis & Theory
The value of `a` is updated from 5 to 10 before printing.
Which operator is used to increase a variable by 1?
A
+ B
++ C
-- D
+=
Analysis & Theory
`++` is the increment operator that increases the value by 1.
What will be the value of `x`?
```c
int x = 4;
x += 3;
```
A
4 B
3 C
7 D
1
Analysis & Theory
`x += 3` adds 3 to `x`, resulting in `x = 7`.
What does this code do?
```c
int a = 6;
a *= 2;
```
A
Doubles the value of `a` B
Halves the value of `a` C
Sets `a` to 2 D
Throws an error
Analysis & Theory
`a *= 2` multiplies `a` by 2, resulting in `12`.
Which of the following **changes the value** of a variable in C?
A
int a = 5; B
a = a + 1; C
float b; D
char c;
Analysis & Theory
`a = a + 1;` changes the value of the variable `a`.
What is the final value of `x`?
```c
int x = 8;
x -= 3;
x *= 2;
```
A
5 B
10 C
8 D
10
Analysis & Theory
`x` becomes 5 after subtraction, then 10 after multiplication.
What happens in this code?
```c
int x = 3;
x = x / 2;
```
A
x becomes 1.5 B
x becomes 1 C
x becomes 2 D
Error
Analysis & Theory
Integer division `3 / 2` results in `1` (decimal is truncated).
Which statement correctly **swaps** two values `a` and `b`?
A
`a = b; b = a;` B
`int temp = a; a = b; b = temp;` C
`swap(a, b);` D
`a += b; b = a;`
Analysis & Theory
The temp-variable method safely swaps values.
What will be printed?
```c
int a = 2;
a = a + a * 2;
printf("%d", a);
```
A
4 B
6 C
8 D
2
Analysis & Theory
Multiplication has higher precedence: `a = 2 + (2 * 2) = 6`.
What will this print?
```c
int a = 1;
a++;
++a;
printf("%d", a);
```
A
1 B
2 C
3 D
4
Analysis & Theory
`a++` increases to 2, then `++a` makes it 3.