Function Parameters

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

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

View Full Document Right Arrow Icon
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).
Background image of page 1

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

View Full Document Right Arrow Icon
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)
Background image of page 2
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 */
Background image of page 3

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

View Full Document Right Arrow Icon
Avoid do { printf (“%d”,n %10); } while (n/=10); do { printf (“%d”,n
Background image of page 4
Background image of page 5

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

View Full Document Right Arrow Icon
Background image of page 6
Background image of page 7
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 Right Arrow Icon
Ask a homework question - tutors are online