Static vs Dynamic Scope

Slides:



Advertisements
Similar presentations
Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
1 Storage Duration and Scope –Local and global variables Storage classes –automatic, static, external, register Todays Material.
For(int i = 1; i
Chapter 5: Abstraction, parameterization, and qualification Xinming (Simon) Ou CIS 505: Programming Languages Kansas State University Fall
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Overloading methods review When is the return statement required? What do the following method headers tell us? public static int max (int a, int b)
Dynamic Objects. COMP104 Dynamic Objects / Slide 2 Memory Management * Static Memory Allocation n Memory is allocated at compilation time * Dynamic Memory.
Names and Scopes CS 351. Program Binding We should be familiar with this notion. A variable is bound to a method or current block e.g in C++: namespace.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Guidelines for working with Microsoft Visual Studio 6.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Shorthand operators.
CSCI 130 Scope of Variables Chapter 6. What is scope Parts of program which can access a variable –accessibility –visibility How long variable takes up.
CSC 335 Review Game Exam 2. Teams Andrew, Marshall, Riley, Z Emily, Paul, Dawn, Lisa Gavan, Catharine, David, Alex D Michelle, Matt, Rohan, Jamie Ben,
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
7. Pointers, Dynamic Memory 20 th September IIT Kanpur 1C Course, Programming club, Fall 2008.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
Scope: Portion of the program in which the identifier can be referenced. Various types of scope, my examples are of block scope and global scope.
Chapter 10 Inheritance and Polymorphism
Mixing integer and floating point numbers in an arithmetic operation.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Inheritance & Dynamic Binding. Class USBFlashDrive We better introduce a new class USMBFlashDrive and save() is defined as a method in that class Computer.
Lecture 13: Working with Multiple Programmers. Headers Header files: Each standard library has a corresponding header. The function prototype for all.
COP 2800 Lake Sumter State College Mark Wilson, Instructor.
FUNCTION Dong-Chul Kim BioMeCIS UTA 12/7/
Functions & Pointers in C Jordan Erenrich
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
Pointers Value, Address, and Pointer. Values and Addresses int x, y, z; y x z values of x,
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 7, Feb 6/7, 2013.
The ++ and -- expressions. The ++ and -- operators You guessed it: The ++ and -- are operators that return a value.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
POINTERS IN C Pointer Basics, Pointer Arithmetic, Pointer to arrays and Pointer in functions.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Functions Dr. Sajib Datta Functions A function is a self-contained unit of program code designed to accomplish a particular task. Some functions.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
CSE 374 Programming Concepts & Tools
Functions Dr. Sajib Datta
Dynamic memory allocation and Intraprogram Communication
CSC 253 Lecture 8.
Dynamic memory allocation and Intraprogram Communication
CSC 253 Lecture 8.
CSC 113 Tutorial QUIZ I.
Scope of Variables.
סדר דין פלילי – חקיקה ומהות ההליך הפלילי
أنماط الإدارة المدرسية وتفويض السلطة الدكتور أشرف الصايغ
CSC215 Homework Homework 04 Due date: Oct 14, 2016.
C Storage classes.
CS2011 Introduction to Programming I Methods (II)
CS 180 Assignment 6 Arrays.

Бази от данни и СУБД Основни понятия инж. Ангел Ст. Ангелов.
class PrintOnetoTen { public static void main(String args[]) {
Scope.
Chapter 6 Data Types.
7. Pointers, Dynamic Memory
In C Programming Language
Sampath Kumar S Assistant Professor, SECE
Developing Java Applications with NetBeans
C Data Types and Variable
Developing Java Applications with NetBeans
You must show all steps of your working out.
Question 1.
CIS 110: Introduction to Computer Programming
Dynamic Objects.
Chapter 11 Classes.
Presentation transcript:

Static vs Dynamic Scope Mark Boady

Scopes Static Scope Dynamic Scope Determine Variable Scope at compile time Dynamic Scope Determine Variable Scope at run time Static Scope is most likely what you are used to

Example 1 int x; int main(){ x=2; f(); g(); h(); } Void f() { int x=3; h();} Void g() { int x=4; h();} Void h() { printf(“%d ”,x);} Static Prints out: 2 2 2 Dynamic Prints out: 3 4 2

Example 2 Int m,n; Void hardy(){ printf(“in hardy n =%d”,n); } Void laurel(int n){ printf(“in laurel m=%d\n”,m); printf(“in laurel n=%d\n”,n); Hardy(); } Int main(){ m=50; n=100; printf(“In Main n=%d”,n); Laurel(1); hardy();

Example 2 Static Answer in main program -- n = 100 in laurel -- m = 50 in laurel -- n = 1 in hardy -- n = 100

Example 2 Dynamic Answer in main program -- n = 100 in laurel -- m = 50 in laurel -- n = 1 in hardy -- n = 1 in hardy -- n = 100