functions

functions - Preliminaries Functions C ++ Functions and...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Preliminaries Functions C ++ Functions and Blocks Len Blanks CSC 1253 Introduction To Computer Science I Using C ++ Louisiana State University October 12, 2010 Len Blanks C ++ Functions and Blocks Preliminaries Functions Topics 1 Preliminaries 2 Functions Examples Function Documentation Reference Parameters Len Blanks C ++ Functions and Blocks Preliminaries Functions References The material for this lecture is heavily based on content from The C ++ Programming Language by Bjarne Stroustrup. Big C ++ by Cay Horstmann and Timothy Budd. Len Blanks C ++ Functions and Blocks Preliminaries Functions Examples Function Documentation Reference Parameters Function References A function reference ( call) has the following syntax: function reference : function-name ( argument 1 , argument 2 , . . . , argument n ) Each argument (zero or more of them) is a C ++ expression, the number and type of which must agree with that specified in the function declaration. Len Blanks C ++ Functions and Blocks Preliminaries Functions Examples Function Documentation Reference Parameters Function Definitions A function definition has the following syntax: function definition : type-name function-name ( parameter 1 , parameter 2 , . . . , parameter n ) { statement-list opt } type-name represents the data type of the value returned by the function. Each parameter (zero or more of them) is in the form of a simple variable declaration type-name represents the data type of the value returned by the function. Its purpose is to both declare the function and provide its implementation. Len Blanks C ++ Functions and Blocks Preliminaries Functions Examples Function Documentation Reference Parameters Examples int absolute_value(int x) { if (x < 0) return -x; else return x; } double perimeter_of_a_rectangle(double length, double width) { return 2.0 * (length + width); } bool is_even(int number) { return number % 2 == 0; } Len Blanks C ++ Functions and Blocks Preliminaries...
View Full Document

Page1 / 19

functions - Preliminaries Functions C ++ Functions and...

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

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