Erin's CS stuff

CS stuff!

Functions Quick Guide

Component Application Example Notes
prototype allows programmer to call functions from anywhere in the program
  • a list of function prototypes goes above the main function
  • each function prototype includes
    • the return type of the function
      • this should match the data type of any information that is sent out of the function
    • the name of the function
    • a list of parameters and their data type
      • parameters are like special variables that save the values sent into the function
    • a semicolon
call where in the program the code in the function will run
  • function calls go in anywhere in our program that we want the function's behavior
  • each function call includes
    • a variable and assignment operator if the returned value of a function is being saved
    • the function name
    • a list of arguments and their data type
      • arguments are the actual values sent into the function
  • a semicolon
definition where the code for the function goes
  • function definitions go below the main function
  • the first line of a function definition is the same as the function prototype except that the semicolon is replaced with curly braces
  • all of the functions code goes in between the curly braces
    • anything can go here, even other function calls