exercises/exercises
Justus Klausecker 16a794fbee 111/112: Add exercises for packed structs/unions
The first exercise introduces the `packed` keyword as an alternative for
bitwise operations. Its main goals are establishing a solid understanding
of field order and conveying the fact that packed containers are basically
integers.
It introduces the concept of container layouts and briefly explains the
default `auto` layout before introducing the `packed` layout (but doesn't
touch `extern` at all).
The exercise also presents a real-world use case for packed containers,
namely LZ4 frame descriptors.
Furthermore it covers equality comparisons between packed containers.

The second exercise talks about switch statements with packed containers
and goes into some more detail on packed unions.
2026-03-13 11:21:03 +01:00
..
001_hello.zig minor typos 2026-01-04 14:17:27 +01:00
002_std.zig Fix: Fix grammar at 002_std.zig 2021-08-19 08:59:18 -07:00
003_assignment.zig Replace "−" with "-" in Assigment 3 tutorial text 2022-06-04 17:21:34 -06:00
004_arrays.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
005_arrays2.zig Improve wording in 005 arrays2 for #93 2022-03-19 19:46:29 -04:00
006_strings.zig Revert syntax demo, add note 2022-02-22 02:21:22 +01:00
007_strings2.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
008_quiz.zig New usize explanation 008, etc. 2021-06-14 11:26:04 -04:00
009_if.zig changed 1 to 42 for better understanding 2025-11-28 14:42:58 +01:00
010_if2.zig var to const when posssible 2023-06-22 09:41:41 +00:00
011_while.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
012_while2.zig add spaces 2022-02-11 10:40:22 +00:00
013_while3.zig improve comment on continue expression behavior 2026-02-27 04:07:06 +01:00
014_while4.zig Normalize interrobangs 2021-05-09 13:15:53 -04:00
015_for.zig Updating wording in 'for' exercises 2023-04-30 16:23:35 -04:00
016_for2.zig Revised exercises due to the changes of Zig version 0.11.0-dev.3853 2023-06-26 23:43:39 +02:00
017_quiz2.zig var to const when posssible 2023-06-22 09:41:41 +00:00
018_functions.zig Update 018_functions.zig 2021-08-28 10:25:03 -04:00
019_functions2.zig fix: 019 typo in example function, missing return type 2025-08-11 21:01:47 +01:00
020_quiz3.zig adds missing 'the' to intro text 2023-02-16 00:39:56 +00:00
021_errors.zig use const for variables that are never modified 2022-01-01 02:20:26 +09:00
022_errors2.zig Normalized exercise output, answers (#41) 2021-04-04 16:29:28 -04:00
023_errors3.zig var to const when posssible 2023-06-22 09:41:41 +00:00
024_errors4.zig var to const when posssible 2023-06-22 09:41:41 +00:00
025_errors5.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
026_hello2.zig I/O improvements 2026-01-09 22:56:23 +01:00
027_defer.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
028_defer2.zig Normalize interrobangs 2021-05-09 13:15:53 -04:00
029_errdefer.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
030_switch.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
031_switch2.zig var to const when posssible 2023-06-22 09:41:41 +00:00
032_unreachable.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
033_iferror.zig fix: typos 2025-03-20 21:24:40 +01:00
034_quiz4.zig I/O improvements 2026-01-09 22:56:23 +01:00
035_enums.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
036_enums2.zig Update outdated comments 2023-06-22 12:11:24 +00:00
037_structs.zig changed struct name 'class' into 'role' 2023-08-02 23:29:02 +02:00
038_structs2.zig changed struct name 'class' into 'role' 2023-08-02 23:29:02 +02:00
039_pointers.zig add commas 2026-02-27 03:38:59 +01:00
040_pointers2.zig improving the explanation 2023-04-05 16:11:56 +02:00
041_pointers3.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
042_pointers4.zig Update 042_pointers4.zig 2023-01-12 19:25:06 +01:00
043_pointers5.zig Correct conventional Zig reference vs value passing re #89 2022-07-31 15:58:24 -04:00
044_quiz5.zig "999 is enough for anybody" triple-zero padding (#18) 2021-03-12 18:59:46 -05:00
045_optionals.zig var to const when posssible 2023-06-22 09:41:41 +00:00
046_optionals2.zig Deleted unnecessary pointer. 2024-11-08 22:48:37 +01:00
047_methods.zig the Earth 2024-05-20 21:32:32 +02:00
048_methods2.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
049_quiz6.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
050_no_value.zig fix: oops 2026-03-09 23:24:59 +00:00
051_values.zig Improved the explanation about passing arguments and added an example. 2024-03-14 23:37:14 +01:00
052_slices.zig Update 052_slices.zig 2021-08-30 17:55:32 -04:00
053_slices2.zig zig fmt 2021-11-05 17:47:12 +01:00
054_manypointers.zig Introduce syntax for turning a many pointer to a slice 2023-10-18 19:28:34 +00:00
055_unions.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
056_unions2.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
057_unions3.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
058_quiz7.zig Rephrase instruction for clarity 2024-10-26 20:43:47 +00:00
059_integers.zig Fixed unicode literal 2024-03-08 01:07:57 +01:00
060_floats.zig Fixed description to decimal and scientific notation 2025-10-17 17:59:57 +02:00
061_coercions.zig remove redundant word "a" 2021-12-25 15:21:33 -07:00
062_loop_expressions.zig fix loop else clause explanation 2022-04-22 17:50:10 -07:00
063_labels.zig dev.1711 - switched to multi-object-for-loops 2023-02-21 21:43:40 +01:00
064_builtins.zig Fix two minor typos 2023-11-21 19:09:47 +02:00
065_builtins2.zig Merge pull request 'replace deprecated mem.indexOf with mem.find' (#363) from pebose/exercises:indexof-to-find into main 2026-02-27 19:36:00 +01:00
066_comptime.zig description specified 2023-01-29 17:52:11 +01:00
067_comptime2.zig Added art description 2025-12-07 22:53:34 +01:00
068_comptime3.zig fix 068_comptime3 comment to 'std.Io.Writer.print' 2026-02-27 03:51:12 +01:00
069_comptime4.zig Revised exercises due to the changes of Zig version 0.11.0-dev.3853 2023-06-26 23:43:39 +02:00
070_comptime5.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
071_comptime6.zig fix: 071 update TypeInfo field case to .int 2026-01-10 10:50:37 +01:00
072_comptime7.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
073_comptime8.zig fix whitespace line-endings 2021-11-05 17:46:56 +01:00
074_comptime9.zig Global scope is container-level scope 2023-09-20 22:30:57 +00:00
075_quiz8.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
076_sentinels.zig Fixes several changes in std.builtin.zig 2024-09-02 19:33:59 +02:00
077_sentinels2.zig zig fmt 2021-11-05 17:47:12 +01:00
078_sentinels3.zig Update 078_sentinels3.zig 2023-06-29 21:32:44 +02:00
079_quoted_identifiers.zig Remove trailing whitespace. 2022-05-18 21:39:36 +02:00
080_anonymous_structs.zig 080: Fix @typeName results in comment 2025-05-30 21:54:25 +02:00
081_anonymous_structs2.zig Fix exercises 058 and 081 🔧 2021-09-04 19:00:03 +03:00
082_anonymous_structs3.zig add hint that @field() works differently on types and values 2026-02-27 03:48:11 +01:00
083_anonymous_lists.zig Ensure the exercises use the canonical format 2023-04-18 18:16:19 +02:00
084_async.zig fix whitespace line-endings 2021-11-05 17:46:56 +01:00
085_async2.zig fix whitespace line-endings 2021-11-05 17:46:56 +01:00
086_async3.zig change suspend; to suspend {} 2021-05-24 15:57:59 -04:00
087_async4.zig add ex087 async 4 2021-05-12 21:36:57 -04:00
088_async5.zig No unused fn params 2021-06-30 19:59:25 -04:00
089_async6.zig zig fmt 2021-11-05 17:47:12 +01:00
090_async7.zig fix whitespace line-endings 2021-11-05 17:46:56 +01:00
091_async8.zig Added ex91 - closing in on async! 2021-11-07 20:51:33 -05:00
092_interfaces.zig Converted var to const if there is no mutation in var. 2023-11-21 15:01:22 +01:00
093_hello_c.zig Update exercises/093_hello_c.zig 2024-01-13 14:27:58 +00:00
094_c_math.zig fix: typo: % instead of @ for a builtin function 2024-05-04 18:51:00 +02:00
095_for3.zig emphasize that the end number of a for-loop range is exclusive 2026-02-27 03:45:09 +01:00
096_memory_allocation.zig Fix some typos 2024-05-06 09:13:56 +02:00
097_bit_manipulation.zig Changed the values for better understanding 2025-05-12 21:36:37 +02:00
098_bit_manipulation2.zig Fixed 98 2025-07-22 10:24:22 +02:00
099_formatting.zig Formatting 2025-12-24 01:10:39 +01:00
100_for4.zig Use print alias in exercise 100_for4.zig 2025-01-07 15:21:36 +00:00
101_for5.zig Add link to DoD talk in 101_for5.zig 2023-08-17 19:43:13 +02:00
102_testing.zig Wrap comment at 80 chars in 102. 2025-10-24 11:54:25 -04:00
103_tokenization.zig Merge pull request 'improve grammar in 103_tokenization' (#365) from pebose/exercises:improve-grammar into main 2026-02-27 19:54:41 +01:00
104_threading.zig changed 'sleep' to async I/O 2025-11-28 14:22:51 +01:00
105_threading2.zig fix: typos 2025-03-20 21:24:40 +01:00
106_files.zig I/O improvements 2026-01-09 22:56:23 +01:00
107_files2.zig I/O improvements 2026-01-09 22:56:23 +01:00
108_labeled_switch.zig 108: . 2025-06-01 01:08:07 +02:00
109_vectors.zig Fixed formating, created patch file. 2024-11-07 15:01:59 +01:00
110_quiz9.zig fix: typos 2025-03-20 21:24:40 +01:00
111_packed.zig 111/112: Add exercises for packed structs/unions 2026-03-13 11:21:03 +01:00
112_packed2.zig 111/112: Add exercises for packed structs/unions 2026-03-13 11:21:03 +01:00
999_the_end.zig changed 'the_end' to '999_the_end' 2023-01-22 13:12:53 +01:00