≈ the.bay.news

Swapping variables?

Ziggit
Swapping variables?
Is there any syntax sugar for swapping variables in Zig? (e.g. a, b = b, a) I expected const std = @import("std"); pub fn main() void { var a: i32 = 42; var b: i32 = 69; std.debug.print("{}, {}\n", .{ a, b }); a, b = .{ b, a }; std.debug.print("{}, {}\n", .{ a, b }); } to work, but it outputs $ zig build run 42, 69 69, 69 which is confusing. Explaining what’s going on here, and whether there’s a syntax sugar will be really appreciated!

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.