Exam3_review - CGS 2425 C+ - Exam 3 Review VARIABLES...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CGS 2425 C++ - Exam 3 Review VARIABLES Variables MUST be declared before using them!!!! Always!!! Variables MUST be given values before using them. For example, if you are adding numbers into a variable, the variable MUST be set to some initial value beforehand. FUNCTIONS Prototype (before main ): return_type funName( var_type varName, var_type varName, . ..); Implementation (after end of main ): return_type funName( var_type varName, var_type varName, . ..) { // statements return returnValue; // only if return_type is not void } Function call : variable = funName(var1, var2, . ..); // if return type is not void funName(var1, var2, . ..); // if return type is void Passing by value : A copy of the variable’s value is passed into the function. Changes made to the variable inside the function are not seen by the calling program. Passing by reference (passing by address) : The address of the variable is passed into the function. Changes made to the variable are seen by the calling program. o Example prototype: void swap( int &a, int &b); o Example function call: swap(x,y); Void functions have no return value; they CANNOT be used in a cout or assignment statement. ARRAYS Arrays are ALWAYS passed by reference in functions. o
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/05/2011 for the course CGS 2421 taught by Professor Onal during the Fall '09 term at University of Florida.

Page1 / 3

Exam3_review - CGS 2425 C+ - Exam 3 Review VARIABLES...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online