Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 25

– Loops;

– Functions;
– Pass by value or by reference;
– Variable scope; and
– Arrays.
Revision
• Where to put your functions???
Option 1
• Place your function before the main function
• Requires to put the function before it first use
by any other function.
Option 2
• Place your function after the main function
• Problem: The compiler works top down. It will
complain about undefined functions..
• Unless … You put a so-called prototype before
all functions.
• Scope
• Two different scopes to care about
• Local scope: Relevant within one function..
• Global scope: The scope defined by the entire
file.
Local Scope - Where to put your variables?
Global Scope
Global Scope
• Not a good idea!!!
Value Parameters
Reference Parameter
Arrays
• They are used to store a group of objects/
variables.

• All elements of an array must be of the same


data type
Arrays
• Define:
• double values[] = { 32, 54, 67.5, 29, 35, 80,
115, 44.5, 100, 65 };
• values[5] = 80
• Arrays demo…find minimum value!
• Convert to find
– Max
– Ave
– Console printing

You might also like