ARGUMATENTS.pptx
Document Details
Uploaded by MercifulFaith
The Aga Khan University
Related
- PCSII Depression/Anxiety/Strong Emotions 2024 Document
- A Concise History of the World: A New World of Connections (1500-1800)
- Human Bio Test PDF
- Vertebrate Pest Management PDF
- Lg 5 International Environmental Laws, Treaties, Protocols, and Conventions
- Fármacos Anticoncepcionais e Disfunção Erétil PDF
Full Transcript
Passing Arguments and Returning Values SLO # 14.2 write a program to invoke a user defined function and pass arguments by constants, value and reference 14.2.1 Call By Value Call By Reference While...
Passing Arguments and Returning Values SLO # 14.2 write a program to invoke a user defined function and pass arguments by constants, value and reference 14.2.1 Call By Value Call By Reference While calling a function, While calling a function, we instead of passing the values pass values of variables to of variables, we pass address it. Such functions are known of variables(location of as “Call By Values”. variables) to the function known as “Call By References. In this method, the value of In this method, the address of each variable in calling function actual variables in the calling is copied into corresponding function are copied into the dummy variables of the called dummy variables of the called function. function. When to use each?? Use Passing by value when. Use passing by reference when: We want to ensure that the original We want the function to modify the original variable remains unchanged. variable. working with small data types (e.g., int, You are dealing with large objects and classes char, etc.). where copying would be inefficient. // Swap functions that // Function swaps Prototype // two values void swapx(int x, int void swapx(int x, int Call by value y); y) // Main function { int main() int t; { t = x; x = y; int a = 10, b = 20; y = t; // Pass by Values cout