logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    sfolax6776
    Feb 19, 2020
      ·  Edited: Nov 09, 2020

    7.7 What happens when passing arrays to a function? What is a reference?

    in Introduction to Java

    A. Introduction

    We discussed the scope of local variables in 7.6. A local variable is only visible in the function/method where it is declared. But what happens to function/method parameters which are defined in the caller method but their values are passed to another function as inputs? Obviously, these parameters are visible in the caller function, but what happens when their values are passed to the called function? Will the changes made in the called function be returned to the caller?

    As a matter of fact, passing individual variables and passing arrays are a bit different. When passing individual variables, copies of variable values are passed to the called methods as inputs; but when the parameters are arrays, references of the arrays are passed to the called methods, which may result in completely different outcomes.


    B. Watch (PPT)


    C. Try:

    1. Create a function to return the maximum value of an int array

    2. Create a function to save the maximum value of an int array as its first element, while the rest values are still saved in the same array.



    0 comments
    0
    0 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners