1EE140: Introduction to 0toductotoProgramming Concepts for EngineersLecture 6 1FunctionsOverviewDefine and call a functionFunction prototypeScope of a variable2Define a functionA simple C function is a namedblock of statementsach function is used to solve a problemEach function is used to solve a problemreturn_type name (type1 var1, type2 var2, ...){Function nameThe type of value returned by the function. If no value will be returned by the function, we use void as the return type.Input parameters, each must have a data type. Use () or (void) if no parameterThis line is the function header3variable declarations;statements;return value;}ouble area (double radius)Define a function to calculate the area of a circlenction name:reaDefine and call a functiondouble area (double radius){double a;a=PI*radius*radius;return a;}function name: areafunction input: double radiusfunction output: doubleCall a functionx=area (i);4statement calls or invokes the function area()value of ‘i’ is passed to area() and copied to the parameter ‘radius’. You can use same name if you want. the value returned by area() is assigned back to ‘x’();

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