[ENGR 101] - Midterm Exam Guide - Comprehensive Notes for the exam (11 pages long!)

214 views11 pages
School
Department
Course
Professor

Document Summary

Function is an abstraction over a chunk of computation: requires explicit return statement. Implementation contains code to make the function work: can contain any kind of code. Examples: function to square a number int square(int n) return n * n, function to find absolute value. I(cid:373)pro(cid:448)i(cid:374)g a(cid:271)s fu(cid:374)(cid:272)tio(cid:374) (cid:894)(cid:373)ultiple (cid:449)ays, do(cid:374)"t (cid:374)eed else) Calling functions is similar to matlab: square(x, abs(x) C++ vs. matlab: cannot return more than one variable in c+, common to define several functions in the same file. In c++, a return statement determines the return value. Arguments and parameters: functions may have many parameters, each with its own type. I(cid:374)t (cid:272) = fu(cid:374)(cid:272)(cid:894)a, (cid:862)hello(cid:863), (cid:271)(cid:895): first line is called function signature, the ordering of arguments you pass in is used to determine what goes to which parameter. Motivation for functions: make code easier to write/understand. Void functions indicates no return value just to ha(cid:448)e so(cid:373)e (cid:862)side effe(cid:272)t(cid:863: changing pass-by-reference parameters (see below)

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents