Function Part 2 PDF
Document Details
Uploaded by BestKnownHeather
Tags
Summary
This document covers function part 2 and discusses the topics of passing variables to functions, including arguments and parameters. It explains the concept of pass by value and pass by reference, and shows examples in C++.
Full Transcript
Sending Data into a Function Passing Variables to a Function...
Sending Data into a Function Passing Variables to a Function Learning Outcomes 3 Values are passed to a function during the function call: e.g.: pow(a, b)-> passes values of a and b A variable has both a value and a unique address to function pow. At the end of this lecture, you should be able to: (memory location) Function explain parameter passing in programs using: You can pass/send either the variable’s value or Values passed to function are arguments. An argument Pass by Value and Pass by Reference. can also be called an actual parameter. Part 2 use reference variables as parameters. its address to the receiving function using : Pass by value Variables in a function header that hold the values Pass by reference passed as arguments are parameters. A parameter can also be called a formal parameter. An argument will be matched to a parameter. 2 LECTURE 5 3 LECTURE 5 4 LECTURE 5 Pass By Value Concept Pass By Value : Programming Example Passing Multiple Arguments Passing Variables By Value //prototype declaration #include Output : 6 void fun (int x); 5 When calling a function and passing multiple In a pass by value, the computer passes the int main ( ) 5 { arguments: content of each actual variable (argument) to the =7; int a = 5; =5; arguments a 5 parameter of the receiving function (creates a cout