Function Parameters

# Function Parameters - < side effect in loop condition 7...

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

7: Function Parameters There are two types of function parameters: formal parameters (appear in a declaration or a definition of a function) actual parameters (appear in a call to the function).

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

View Full Document
Example /* Function: maxi * Purpose: find the maximum of its integer * arguments * Inputs: two parameters * Returns: the maximum of parameters * Modifies: nothing * Error checking: none * Sample call: i = maxi(k, 3)
Example double oneOverNseries(int n) { double x; int i; if(n <= 0) return 0; for(x = 1, i = 1; i < n; i++) x += 1/((double)i); return x; } /* Check boundary conditions */

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

View Full Document
Avoid do { printf (“%d”,n %10); } while (n/=10); do { printf (“%d”,n

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %10); <-- side effect in loop condition 7: void and Conversions • Definition: • int f() is equivalent to int f(void) • Call: • f(); is equivalent to (void)f(); • 7: exit Function • To terminate the execution of an entire program: • exit(int code); • double f(double x) { • if(x < 0) { • fprintf(stderr, "negative x in %s\n", ◆ double v = f(2.5); /* call before decl. */ double f() { … } ◆ double f() { return 2.5; } A double f () ◆ double f(double v) { if(v == 0) return; } • The code parameter of exit() should be one of the two values: EXIT_SUCCESS or EXIT_FAILURE . Errors...
View Full Document

{[ snackBarMessage ]}

### Page1 / 7

Function Parameters - < side effect in loop condition 7...

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

View Full Document
Ask a homework question - tutors are online