Module 6: Functions

CMPS 162: Introduction to Programming

Introduction

Functions, also known as subroutines, are the building blocks of larger programs. A function completes a subtask in the overall program and can be invoked many times with different inputs (resulting in different outputs). For example, one could write a function to find the largest element in an array. When the function is invoked with a different array a different answer will be returned. One of the most challenging tasks in programming is to take a problem and solve it by dividing it into several functions that collectively give an answer to the problem. We will see how data can be passed to a function by the caller, and how a function can return data to the caller. There is also an important difference between local and global variables that we will investigate.

Module Objectives

  • Describe functions
  • Show passing data to functions
  • Show passing data back from functions
  • Explain the difference between local and global variables

Learning Resources

  • Module 6 Readings: Chapters 35 thru 38 from Myers

Learning Activities

  • Module 6 Assignment: Interactive Coding Exercises 35 thru 38

For Further Study

Leave A Reply

Your email address will not be published. Required fields are marked *