Docsity

Mathematical Function - Lecture Slides | CMSC 106, Study notes of Computer Science

Partial preview of the text

Download Mathematical Function - Lecture Slides | CMSC 106 and more Study notes Computer Science in PDF only on Docsity!

CMSC 106Lecture Set

Set Started:

Tuesday, October 9, 2007



Function definition



Gives a name to a group of statements which can then beexecuted (called) just using that name.



Mathematical functions

sin(x) = y

^

^

^

function's result

+-- argument

| +-- function name



In C, function result is called return value

Simple example functiondefinition:

void

error_msg(void) {

printf("This ");printf("is Bad Input\n");

return;

function

name

= "error_msg"

return type

= nothing

list of parameters

= empty

body

has only three statements

Calling (executing) a function:



general form:



function-name(any arguments)



as a statement: 

printf("Hello,");



or as an expression in assignment: 

ch = getchar();



or as an expression being tested in a

condition:



while (!feof(stdin))

Examples



parameter passing example



return value example



function calling function example