summaryrefslogtreecommitdiff
path: root/exercises/116_defer3.zig
blob: 6e3cf6df830c19f719596aded9961356fd8d6cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//
// When there are multiple defers in a single block, they are executed in reverse order.
//
const std = @import("std");

pub fn main() void {
    var x: u32 = 100;
    {
        // Try reordering the statements to get the answer 42
        defer x = x / 10;
        defer x = x + 11;
        defer x = x * 2;

        // It might seem silly in this example, but it's important to know when
        // deinitializing containers whose elements need to be deinitialized first.
    }
    std.debug.print("{d}\n", .{x});
}