Demonstrate polymorphism in Go.
Explore the precedence and semantics of memory operators & and * in Go.
In Go, you cannot increment a pointer using ptr++.
Because increment and decrement operations can’t be used as expressions, only as statements. Also, only the postfix notation is allowed.
Without pointer arithmetic, the convenience value of By removing the pre- and postfix increment operators drops. By removing them from from the expression hierarchy altogether, expression syntax is simplified and the messy issues around the order of evaluation of
p[i] = q[++i]) are eliminated as well. The simplification is significant.
Unary operators have the highest precedence. As the
-- operators form statements, not expressions, they fall outside the operator hierarchy. As a consequence, statement
*p++ is the same as
In Go, you cannot increment a pointer using ptr++the first example, the pointer points to the address of n at first. Then it gets dereferenced--the value of the pointer is 20. After the increment, the value becomes 21.
In the second example, the pointer first points to index 0 of the array. The only way to increment the location of pointer is to specify the new index.
After moving the pointer to index 1 of the array, the dereferenced pointer gets evaluated to 2, which is the second element in the array.