In this video, learn about how parameters are passed to function and see how some types are passed by value and some by reference. Also, learn about using pointers to pass values by reference.
- [Instructor] DoubleAt is a function…that takes a slice of integers…and an index and doubles the value at that index.…Here in main we create a slice of values,…one, two, three and four,…then call our function…saying that we want to double the value at index number two…and then we are going to print it out.…Let's save it and run.…Go run params.go…and we see one, two, six and four.…
Remember that Go uses zero-based indexing,…so two is the third element.…Here's another function.…This one gets an integer…and doubles its value.…Let's use double in our code.…We say that val equals to 10,…we call double(val)…and then we'll print the value out.…Let's save this one and run it.…
And we see that the original value hasn't changed.…What happened?…When Go passes an integer to a function,…Go passes it by value…which means Go will create a copy of this integer…and pass it to the function.…Any changes to the integer inside the function…won't affect the original value.…However, when Go passes a slice or a map to a function,…it passes it by reference.…
- Go basic types, conditionals, and loops
- Go functions
- Object-oriented programming with Go
- Error handling
- Concurrent programming with channels
- Testing and project management
- Networking with JSON and HTTP
Skill Level Beginner
Programming Foundations: Fuzzy Logicwith Erin Colvin41m 50s Intermediate
Getting started1m 34s
1. Getting Started
2. Go Basics
5. Error Handling
7. Project Management
Next steps1m 12s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.