# Parameters and Overloading - Lecture 2: Parameters and...

This preview shows pages 1–7. Sign up to view the full content.

Lecture 2: Parameters and Overloading CS256 – Fall 2008

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Outline Parameters Call by value and call by reference Overloading Default arguments Default arguments and overloading Coverage: Chapter 4 of textbook
Function definition and declaration Function declaration double f(int x, int y); Function definition double f(int x, int y) {return (x+y)/2.0); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Parameters Call by value parameters double total (int feet, int inches) { inches = 12*feet + inches; return inches; } Call by reference parameters cout << “enter a real number as input number\n”; cin >> data; return; } Exercises swap example Self-test exercise 3 (p143)
Overloading Function overloading double average (double n1, double n2) { return (n1+n2)/2.0; } double average (double n1, double n2, double n3) { return (n1+n2+n3)/3.0; } cout << average(3.5, 2.5); cout << average(3.5, 2.5, 2.0);

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Function’s Signature A function’s signature is the function’s
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/18/2008 for the course CS 256 taught by Professor Dr. yang during the Fall '08 term at Cal Poly Pomona.

### Page1 / 14

Parameters and Overloading - Lecture 2: Parameters and...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online