Skip to content

Commit

Permalink
Fix lab 1 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 authored and edi33416 committed Oct 25, 2022
1 parent 40a7553 commit 94f509d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Introduction to D/lecture/arrays/array_setting.d
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ void main()
int[] b = [1, 2, 3, 4, 5];
a = 3; // set all elements of a to 3
a[] = 2; // same as `a = 3`; using an empty slice is the same as slicing the full array
b = a[0 .. $]; // $ evaluates to the length of the array (in this case 10)
b = a[0 .. $]; // $ evaluates to the length of the array (in this case 3)
b = a[]; // semantically equivalent to the one above
b = a[0 .. a.length]; // semantically equivalent to the one above
b[] = a[]; // semantically equivalent to the one above
Expand Down
2 changes: 2 additions & 0 deletions Introduction to D/lecture/arrays/vector.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ void main()
int[] b;
int[] c;

b.length = 3;
c.length = 3;
b[] = a[] + 4; // b = [5, 6, 7]
c[] = (a[] + 1) * b[]; // c = [10, 18, 28]
}
6 changes: 3 additions & 3 deletions docs/intro/quiz/slice.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ nav_exclude: true
## Slices quiz

{% assign q1_text = "Why, for the previous example, the lengths of a and b are different?" %}
{% assign q1_choices = "`a` and `b` have the same lengths| `b` refers the same data as `a`, but it has no length constraints| a copy of `a` was saved into `b`, a dynamic array, and then the value 5 was appended to the dynamic array| operator `~` works for slices, but it has no impact on static arrays" | split: "| " %}
{% assign q1_feedbacks = "`a` is a static array, so it's length is fixed, but we can still append data in that particular memory zone through a different reference| Correct!| `a` is a static array, so it's length is fixed, but we can still append data in that particular memory zone through a different reference| `a` is a static array, so it's length is fixed, but we can still append data in that particular memory zone through a different reference" | split: "| " %}
{% assign q1_correct = 1 %}
{% assign q1_choices = "`a` and `b` have the same lengths | `b` refers the same data as `a`, but it has no length constraints so `5` is simply appended in place | `b` is allocated a new memory region when `5` is concatenated to it | operator `~` works for slices, but it has no impact on static arrays" | split: "| " %}
{% assign q1_feedbacks = "`a` is a static array, so it's length is fixed, but appending data to it through `b` results in: allocating new memory for `b`, copying the contents of `a` to `b` and adding the new elements (`5` in this case) to the end of the array| `a` is a static array, so it's length is fixed, but appending data to it through `b` results in: allocating new memory for `b`, copying the contents of `a` to `b` and adding the new elements (`5` in this case) to the end of the array| Correct!| `a` is a static array, so it's length is fixed, but appending data to it through `b` results in: allocating new memory for `b`, copying the contents of `a` to `b` and adding new elements (`5` in this case) to the end of the array | split: "| " %}
{% assign q1_correct = 2 %}
{% include mc-quiz.html text=q1_text choices=q1_choices answer=q1_correct feedback=q1_feedbacks %}

0 comments on commit 94f509d

Please sign in to comment.