2021-01-03 18:55:45 -05:00
|
|
|
//
|
2021-02-07 11:06:51 -05:00
|
|
|
// It seems we got a little carried away making everything "const u8"!
|
|
|
|
//
|
|
|
|
// "const" values cannot change.
|
|
|
|
// "u" types are "unsigned" and cannot store negative values.
|
|
|
|
// "8" means the type is 8 bits in size.
|
|
|
|
//
|
|
|
|
// Example: foo cannot change (it is CONSTant)
|
|
|
|
// bar can change (it is VARiable):
|
|
|
|
//
|
|
|
|
// const foo: u8 = 20;
|
|
|
|
// var bar: u8 = 20;
|
|
|
|
//
|
|
|
|
// Example: foo cannot be negative and can hold 0 to 255
|
2022-06-04 19:21:34 -04:00
|
|
|
// bar CAN be negative and can hold -128 to 127
|
2021-02-07 11:06:51 -05:00
|
|
|
//
|
|
|
|
// const foo: u8 = 20;
|
2021-02-14 12:04:04 -05:00
|
|
|
// const bar: i8 = -20;
|
2021-02-07 11:06:51 -05:00
|
|
|
//
|
|
|
|
// Example: foo can hold 8 bits (0 to 255)
|
|
|
|
// bar can hold 16 bits (0 to 65,535)
|
|
|
|
//
|
2021-02-12 23:41:33 -05:00
|
|
|
// const foo: u8 = 20;
|
2021-02-13 23:06:48 -05:00
|
|
|
// const bar: u16 = 2000;
|
2021-02-12 23:41:33 -05:00
|
|
|
//
|
2021-02-07 11:06:51 -05:00
|
|
|
// You can do just about any combination of these that you can think of:
|
2021-02-15 16:55:44 -05:00
|
|
|
//
|
2021-02-07 11:06:51 -05:00
|
|
|
// u32 can hold 0 to 4,294,967,295
|
2022-06-04 19:21:34 -04:00
|
|
|
// i64 can hold -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
|
2021-02-07 11:06:51 -05:00
|
|
|
//
|
|
|
|
// Please fix this program so that the types can hold the desired values
|
|
|
|
// and the errors go away!
|
2021-01-03 18:55:45 -05:00
|
|
|
//
|
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
pub fn main() void {
|
2024-01-10 02:52:58 -05:00
|
|
|
var n: u8 = 50;
|
2021-01-03 18:55:45 -05:00
|
|
|
n = n + 5;
|
|
|
|
|
2024-01-10 02:52:58 -05:00
|
|
|
const pi: u32 = 314159;
|
2021-01-03 18:55:45 -05:00
|
|
|
|
2024-01-10 02:52:58 -05:00
|
|
|
const negative_eleven: i8 = -11;
|
2021-01-03 18:55:45 -05:00
|
|
|
|
|
|
|
// There are no errors in the next line, just explanation:
|
|
|
|
// Perhaps you noticed before that the print function takes two
|
|
|
|
// parameters. Now it will make more sense: the first parameter
|
|
|
|
// is a string. The string may contain placeholders '{}', and the
|
2021-01-06 17:41:53 -05:00
|
|
|
// second parameter is an "anonymous list literal" (don't worry
|
|
|
|
// about this for now!) with the values to be printed.
|
2021-02-15 16:55:44 -05:00
|
|
|
std.debug.print("{} {} {}\n", .{ n, pi, negative_eleven });
|
2021-01-03 18:55:45 -05:00
|
|
|
}
|