1/25
Beginner Zig (0.15.1) programming language + Zigbash flashcards.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
To run a Zig file, you must run the command—
zig build
To run a Zig file with debugging purposes, not focused on output, you must run the command—
zig test
Zig functions are, by default, are—
Private
The main()
function should usually be—
Public
A function is made public with the pub
statement
True
pub fn foo() void {
...
}
This example function is made—
Public
Returns a value which represents imported code—
const foo = @import("foo")
Imports must be declared as ________ because they can only be used at _______ time rather than ___ time.
constants, compile, run
_____ values cannot change.
const
_ types are “unsigned“ and cannot store negative values.
u
_ means the type is 8 bits in size.
8
const foo: u8 = 20;
var bar: u8 = 20;
Can foo
change? Why?
No, because it is a constant.
const foo: u8 = 20;
var bar: u8 = 20;
Can bar
change? Why?
Yes, because it is a variable.
const foo: u8 = 20;
const bar: i8 = -20;
foo
can be negative?
False
const foo: u8 = 20;
var bar: i8 = 20;
foo
can hold 0
to 255
or -128
to 127
?
0
to 127
.
const foo: u8 = 20;
var bar: i8 = 20;
bar
can be negative?
True
const foo: u8 = 20;
var bar: i8 = 20;
bar can hold 0
to 255
or -128
to 127
?
-128
to 127
const foo: u8 = 20;
const bar: u16 = 2000;
foo can hold _ bits; 0
to ___
8
; 255
const foo: u8 = 20;
const bar: u16 = 2000;
bar can hold _ bits; 0
to _____
16
; 65535
The print
function takes _ parameters.
2
The first parameter of the print
function is a ______.
string
Should there be outside information, the second parameter of the print function is an _________ ____ _______.
anonymous list literal
var n: u8 = 50;
const pi: u32 = 314159;
const negative_eleven: i8 = -11;
std.debug.print("{} {} {}\n", .{n, pi, negative_eleven});
Assume this is the main function and all necessary imports are called. What is printed?
55 314159 -11
var foo: ?????? = [3]u32{ 42, 108, 5423};
Fill in the array.
[3]u32
When Zig can infer the size of the array, you can use _ for the size. You can also let Zig infer the ___ __ _____ so the declaration is much less verbose.
_; type of value