D Language Dynamic Arrays & Slices Slices


Example

import std.stdio;

void main() {
    int[] arr = [1, 2, 3, 4, 5];
 
    auto arr2 = arr[1..$ - 1]; // .. is the slice syntax, $ represents the length of the array
    writeln(arr2); // [2, 3, 4]

    arr2[0] = 42;
    writeln(arr[1]); // 42
}