1//! this is a top level doc, starts with "//!"
3const std = @import("std");
5pub fn main() anyerror!void {
6 const stdout = std.io.getStdOut().writer();
7 try stdout.print("Hello, {}!\n", .{"world"});
10const expect = std.testing.expect;
13 // comments start with "//" until newline
15 const x = true; // another comment
19/// a doc comment starts with "///"
20/// multiple lines are merged together
21const Timestamp = struct {
22 /// number of seconds since epoch
25 /// number of nanoseconds past the second
30 pub fn unixEpoch() Self {
38const my_val = switch (std.Target.current.os.tag) {
50const TokenType = union(enum) {
56const array_lit: [4]u8 = .{ 11, 22, 33, 44 };
57const sentinal_lit = [_:0]u8{ 1, 2, 3, 4 };
59test "address of syntax" {
60 // Get the address of a variable:
64 // Dereference a pointer:
65 expect(x_ptr.* == 1234);
67 // When you get the address of a const variable, you get a const pointer to a single item.
68 expect(@TypeOf(x_ptr) == *const i32);
70 // If you want to mutate the value, you'd need an address of a mutable variable:
73 expect(@TypeOf(y_ptr) == *i32);
75 expect(y_ptr.* == 5679);
79const decimal_int = 98222;
81const another_hex_int = 0xFF;
82const octal_int = 0o755;
83const binary_int = 0b11110000;
85// underscores may be placed between two digits as a visual separator
86const one_billion = 1_000_000_000;
87const binary_mask = 0b1_1111_1111;
88const permissions = 0o7_5_5;
89const big_address = 0xFF80_0000_0000_0000;
92const floating_point = 123.0E+77;
93const another_float = 123.0;
94const yet_another = 123.0e+77;
96const hex_floating_point = 0x103.70p-5;
97const another_hex_float = 0x103.70;
98const yet_another_hex_float = 0x103.70P-5;
100// underscores may be placed between two digits as a visual separator
101const lightspeed = 299_792_458.000_000;
102const nanosecond = 0.000_000_001;
103const more_hex = 0x1234_5678.9ABC_CDEFp-10;
105fn max(comptime T: type, a: T, b: T) T {
106 return if (a > b) a else b;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list