Printing to the screen
To print text on the screen, we use a function from Zig’s Standard Library, std. In this context, standard means the library is bundled with the language.
Its components are basic utilities, like the print function we’ll use to show a message.
Create a file named hello.zig and place inside the code that prints a “Hello world”.
hello.zig |
|
pub fn main() void { @import("std").debug.print("Hello world!\n", .{}); } |
To run this code, execute the following in your command line:
|
$ zig run hello.zig |
|
Hello world! |
Congratulations! You’ve just written your first program in Zig - the classic “Hello world”.
What’s that \n? It’s a symbol that marks a line break. We’ll get into it later.