This code above, i can understand that slice length is increased on demand actually the compiler expands the underneath array so the appended value is not displayed in the main function.
The only way to append 100 is pass by pointer or return the slice and reassign so its reflected in main()
Why is way to get this reflected in main function other than above two ways ?
Maybe i am missing to understand something ? Can someone help and clarify please ?
This is because every-time when slice is being appended/modified, a new slice is created as intended. Since the append operation is in different memory space (inside a different function), it didn’t update the intended memory space (in main()).
Passing in as a memory pointer and then let the function update it accordingly (my preferred way as the function is self-explanatory sharply that it only updates existing memory).
returning the slice as a result and then update the slice in main().