The Run-Time Stack and Reference Parameters

Slides:



Advertisements
Similar presentations
Operator overloading redefine the operations of operators
Advertisements

Chapter 6 Advanced Function Features Pass by Value Pass by Reference Const parameters Overloaded functions.
Functions Prototypes, parameter passing, return values, activation frams.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
More on Functions Programming. COMP104 Lecture 19 / Slide 2 Passing Parameters by Reference l To have a function with multiple outputs, we have to use.
Pointers CS 308 – Data Structures. Getting the address of a variable You need to use the address operator & #include void main() { int num; num = 22;
Monday, 9/23/02, Slide #1 CS 106 Intro to CS 1 Monday, 9/23/02  QUESTIONS??  Today:  Discuss Lab 3  Do Exercises  Introduction to functions  Reading:
Programming Functions: Passing Parameters by Reference.
C++ Pointers Copies from SEE C++ programming course and from Starting Out with C++: Early Objects, 8/E by Tony Gaddis, Judy Walters and Godfrey Muganda.
Functions g g Data Flow g Scope local global part 4 part 4.
CS1201: Programming Language 2 Recursion By: Nouf Almunyif.
Chapter 9 Pointers Fall 2005 Csc 125 Introduction to C++
Functions Pass by Reference Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Fall 2005.
Pointers Chapter 9. Getting The Address Of A Variable Each variable in program is stored at a unique address Use address operator & to get address of.
Pointers CSE 5100 Data Structures and Algorithms.
Passing Data - by Reference Syntax && double Pythagorus(double &, double &); Pythagorus(height, base); & & double Pythagorus(double& a, double& b) function.
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Review 1 List Data Structure List operations List Implementation Array Linked List.
Input a number #include using namespace std; int main() { int num; cout num; return 0; }
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
Quiz // // The function exchanges the two parameters. // Param: ( ) // Param:
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
1 CS1430: Programming in C++ Section 2 Instructor: Qi Yang 213 Ullrich
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Constructors Initializing New Objects #include “fraction.h” int main() { float x; float y = 6.7; float z(7.2); Fraction.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
The Basics of Arrays Problem: How can the rancher easily catalog all of his cattle?
Activation Record int main() { float allScores[MAX_ROWS][MAX_COLS]; int rows, cols; GetAllData(allScores, rows, cols);... } 1 void GetAllData(float a[][MAX_COLS],
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Lecture 10 Oct 7, 02. Pass by value and reference ► Calling a function and passing the value of a variable as an argument is called pass by value. The.
Arrays float Scores[9]; ? index: element // one dimensional array 2.
Pointers Lecture: 5. Topics 1 Pointers and the Address Operator 2 Pointer Variables 3 The Relationship Between Arrays and Pointers 4 Pointer Arithmetic.
Static Variables. Function Scope  “Normal” local variables go out of scope and are deallocated when a function terminates.
1 C++ Classes and Data Structures Course link…..
MT262A Review.
Standard Version of Starting Out with C++, 4th Edition
Chapter 5 Function Basics
CS 1430: Programming in C++.
לולאות קרן כליף.
CS 1430: Programming in C++.
Function Basics.
understanding memory usage by a c++ program
פונקציות לעיתים קרובות לא נוח להגדיר את כל התוכנה בתוך גוף אחד.
Null-Terminated Character Arrays
Alternate Version of STARTING OUT WITH C++ 4th Edition
אבני היסוד של תוכנית ב- C++
אבני היסוד של תוכנית ב- C++
Working With Arrays.
CS150 Introduction to Computer Science 1
Counting Loops.
Pointers & Functions.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Lec 14 Oct 23, 02.
CS150 Introduction to Computer Science 1
Default Arguments.
Function Overloading.
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Pointers & Functions.
Standard Version of Starting Out with C++, 4th Edition
Functions Divide and Conquer
CS150 Introduction to Computer Science 1
Presentation transcript:

The Run-Time Stack and Reference Parameters

float average (const float val1, const float val2) { ? 4 6 ? 5 ? num1 num2 the_average main() ? 4 6 ? 5 4 ? float average (const float val1, const float val2) { float ave = (val1+val2)/2; return ave; } int main() {     float num1=4, num2=6, the_average=4;     the_average = average (num1, num2);     return 0; }

void swapVal (int val1, int val2) {     int temp = val1;     val1 = val2;     val2 = temp;     return; } void swapRef (int & val1, int & val2) {     int temp = val1;     val1 = val2;     val2 = temp;     return; } int main() {     int a = 7, b = 2;     cout<<a<<" "<<b<<endl;     swapVal(a, b);     cout<<a<<" "<<b<<endl; swapRef(a, b); cout<<a<<" "<<b<<endl; ...

void get_point(float & x, float & y) { cout << “enter x value”; b main() a ? 5 8 ? void get_point(float & x, float & y) { cout << “enter x value”; cin >> x; cout << “enter y value”; cin >> y; return; } int main() {     float a, b;     get_point (a, b); ...

End of Session