Nate Brunelle Today: Functions again, Scope

Slides:



Advertisements
Similar presentations
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Advertisements

Scope and Lifespan of Identifiers. Every function has a scope What does that mean? That means that every identifier that is created in a function (that’s.
1 5.3 Sub Procedures, Part II Passing by Value Passing by Reference Sub Procedures that Return a Single Value Debugging.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 7: User-Defined Functions II.
Q and A for Chapter 3.4 – 3.14 CS 104 Victor Norman.
Chapter 15 Memory Management: Four main memory areas for a C++ program: Code: code for instructions, methods, etc. static data: Global variables (declared.
CS 330 Programming Languages 10 / 14 / 2008 Instructor: Michael Eckmann.
Fall 2008ACS-1805 Ron McFadyen1 Ch 8 Recursion Recursion occurs when a method (or function) calls itself.
CS-212 Classes (cont) Dick Steflik. Member functions Member functions of a class include – getters used to retrieve state data – setters used to set state.
VB – Core III Functions Sub-routines Parameter passing Modules Scope Lifetime.
©2004 Brooks/Cole Chapter 6 Methods and Scope. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 A Method Can Be Viewed as a Black Box To use a.
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Advanced Functions Lecture 14: Supporting Material Dr Kathryn Merrick Tuesday 21 st April, 2009.
Object Oriented Programming Elhanan Borenstein Lecture #3 copyrights © Elhanan Borenstein.
 Constructor  Finalize() method  this keyword  Method Overloading  Constructor Overloading  Object As an Argument  Returning Objects.
Julian on JavaScript: Functions Julian M Bucknall, CTO.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
User-Defined Functions II TK1914: C++ Programming.
CMSC 150 METHODS AND CLASSES CS 150: Wed 25 Jan 2012.
ECE 103 Engineering Programming Chapter 31 C Scopes Herbert G. Mayer, PSU CS Status 8/1/2015 Initial content copied verbatim from ECE 103 material developed.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Department of Electronic & Electrical Engineering Functions Parameters Arguments Pointers/dereference & * Scope Global/Local Storage Static/Automatic.
Tarik Booker CS 242. What we will cover…  Functions  Function Syntax  Local Variables  Global Variables  The Scope of Variables  Making Functions.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
Mechanics of Functions
Test 2 Review Outline.
Chapter 10: Void Functions
Week 8 - Friday CS 121.
Function There are two types of Function User Defined Function
The UK Tier 1 Entrepreneur Visa and the UK Representative of Overseas Business Visa - SmartMove2UK
This pointer, Dynamic memory allocation, Constructors and Destructor
CISC/CMPE320 - Prof. McLeod
Nate Brunelle Today: Pseudo-Code, Party
Activation Records and Function Calls
Chapter 4 (part 2).
Nate Brunelle Today: PyCharm
Variables and Their scope
Passing Parameters by value
Understanding Program Address Space
Chapter 8 Namespaces and Memory Realities
X and Y's of Scientific Method
Procedure Activations
CS2011 Introduction to Programming I Arrays (II)
Herbert G. Mayer, PSU CS Status 8/2/2013
Nate Brunelle Today: Turtles
The Lost Sheep Luke 15: 4-9.
Objects (again) Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction.
CISC/CMPE320 - Prof. McLeod
Nate Brunelle Today: Lists
Nate Brunelle Today: Lists
Nate Brunelle Today: Functions
Nate Brunelle Today: Strings, Type Casting
Nate Brunelle Today: Values and Types
Nate Brunelle Today: Conditional Decision Statements
½ of 6 = 3.
Writing Focus: Personal Narratives
Nate Brunelle Today: Regular Expressions
Nate Brunelle Today: Functions
Nate Brunelle Today: Strings, Type Casting
Nate Brunelle Today: Functions again, Scope
Nate Brunelle Today: Regular Expressions
References Revisted (Ch 5)
CS150 Introduction to Computer Science 1
Nate Brunelle Today: Pseudo-Code
Lecture 20 – Practice Exercises 4
I do belive something happens.
Lecture 20 – Practice Exercises 4
Creating and Using Classes
Parameters and Arguments
Scope Rules.
Presentation transcript:

Nate Brunelle Today: Functions again, Scope CS1110 Nate Brunelle Today: Functions again, Scope

Questions?

Last Time Functions

Visualizing Programs http://www.pythontutor.com/visualize.html

Scope Scope- The area where a variable has meaning Usually: variable is in scope when it is created onward. Functions: variable is in scope only in the function in which it is defined

What happens when you invoke a function? Create memory for the function Copy argument values into parameter names Do what the function says Know what to return Remove the memory for the function

Which variable v is in scope? If the variable v is available in the local scope, use that one If the variable v is not available in the local scope, use the variable v available in the global scope If a function ever will have the local variable v, you can only use that variable v

Global variables Allow you to have something “remembered” from one run of a function to another.