Slices lower and higher bounds issues

primes := [6]int{2, 3, 5, 7, 11, 13}

used in “slices” explanation present on “tour” at location / url / Context:

I am more concerned about the observation 2 stated below

Observation 1:
Let us assume we want to slice value from “primes” array. Hence, we will write some thing like below, with N and M being two integer numbers:

var s[]int = primes[N:M]

N = Low bound = Position of the first number to be copied to slice. Here we use C style reference, hence the position count starts from 0
M = Higher bound
There is however confusion about what value of M should be used:
i. M can be a numeric number that informs how many values need to be copied
ii. M can be the position of the last number that should be a part of the slice:
a. assuming that the first value in the array is at position 0
b. assuming that the first value in the array is at position 1

Based on shared example (shared on tour), the possible description for M is ii.b

A. Why cannot N and M count from 0? Why does N start count from 0 and M from 1?
B. Why cannot we use M as the number of elements we want to keep in slice?

Observation 2:
Also why error is not thrown for “var s[]int = prime[6:6]” (as the permitted values for low bound (i.e. N) are 0 through 5)?

This was answered at Understanding "slices" and its output

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.