221V 1 день назад
Родитель
Сommit
b6c759611e
1 измененных файлов с 26 добавлено и 25 удалено
  1. 26 25
      exercises/054_manypointers.zig

+ 26 - 25
exercises/054_manypointers.zig

@@ -12,31 +12,31 @@
 //
 //
 const std = @import("std");
 const std = @import("std");
 
 
-pub fn main() void {
-    // Take a good look at the array type to which we're coercing
-    // the zen12 string (the REAL nature of strings will be
-    // revealed when we've learned some additional features):
-    const zen12: *const [21]u8 = "Memory is a resource.";
-    //
-    //   It would also have been valid to coerce to a slice:
-    //         const zen12: []const u8 = "...";
-    //
-    // Now let's turn this into a "many-item pointer":
-    const zen_manyptr: [*]const u8 = zen12;
-
-    // It's okay to access zen_manyptr just like an array or slice as
-    // long as you keep track of the length yourself!
-    //
-    // A "string" in Zig is a pointer to an array of const u8 values
-    // (or a slice of const u8 values, as we saw above). So, we could
-    // treat a "many-item pointer" of const u8 as a string as long as
-    // we can CONVERT IT TO A SLICE. (Hint: we do know the length!)
-    //
-    // Please fix this line so the print statement below can print it:
-    const zen12_string: []const u8 = zen_manyptr;
-
-    // Here's the moment of truth!
-    std.debug.print("{s}\n", .{zen12_string});
+pub fn main() void{
+  // Take a good look at the array type to which we're coercing
+  // the zen12 string (the REAL nature of strings will be
+  // revealed when we've learned some additional features):
+  const zen12: *const [21]u8 = "Memory is a resource.";
+  //
+  //   It would also have been valid to coerce to a slice:
+  //         const zen12: []const u8 = "...";
+  //
+  // Now let's turn this into a "many-item pointer":
+  const zen_manyptr: [*]const u8 = zen12;
+  
+  // It's okay to access zen_manyptr just like an array or slice as
+  // long as you keep track of the length yourself!
+  //
+  // A "string" in Zig is a pointer to an array of const u8 values
+  // (or a slice of const u8 values, as we saw above). So, we could
+  // treat a "many-item pointer" of const u8 as a string as long as
+  // we can CONVERT IT TO A SLICE. (Hint: we do know the length!)
+  //
+  // Please fix this line so the print statement below can print it:
+  const zen12_string: []const u8 = zen_manyptr[0..21];
+  
+  // Here's the moment of truth!
+  std.debug.print("{s}\n", .{zen12_string});
 }
 }
 //
 //
 // Are all of these pointer types starting to get confusing?
 // Are all of these pointer types starting to get confusing?
@@ -53,3 +53,4 @@ pub fn main() void {
 //   |  []u8         |  slice of u8s                                |
 //   |  []u8         |  slice of u8s                                |
 //   |  []const u8   |  slice of immutable u8s                      |
 //   |  []const u8   |  slice of immutable u8s                      |
 //   +---------------+----------------------------------------------+
 //   +---------------+----------------------------------------------+
+