CSE 100 Lecture 14: CSE100-Lecture 14

3 Pages
Unlock Document

Arizona State University
Computer Science and Engineering
CSE 100
Xuerong Feng

Lecture 14 6.7 Returning a Value from a Function return statement can be used to return a value from a function to the module that made the function call prototype and function header must indicate data type of return value (not void) calling function should use the returned value assign it to variable sent it to cout use in arithmetic computation use in relational expression Returning a Value the ret tatement Format return expression; expression: may be variable, literal value, or expression expression should be same data type as declared return type of function (will be converted if not) 6.8 Returning a Boolean Value function can return true or false you can declare return type in the function prototype and header as bool function body must contain return statement(s) that return true, false, or bool variables or expressions calling function can use return value in relational expression Boolean return Example bool isValid(int); prototype bool isValid(int val) header { int min = 0, max = 100; if(val >= min val <= max) return true; else return false; } if (isValid(score)) call Programming Style and return statements a programming style may calculate a return value and use a single return statement. Previous example could be bool isValid(int val) header { bool result; int min = 0, max = 100; if(val >= min val <= max) result = true;
More Less

Related notes for CSE 100

Log In


Don't have an account?

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.