{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

04FunctionsLarge

# 04FunctionsLarge - should have a return statement where the...

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

1 CMSC 106 Lecture Set #4 Set Started: Friday, September 16, 2011 square6 Function definition square6 Gives a name to a group of statements which can then be executed (called) just using that name. square6 Mathematical functions sin(x) = y ^ ^ ^ | | | | | function's result | | | +-- argument | +-- function name square6 In C, function result is called return value .

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

View Full Document
2 Defining a function square6 Functions must be defined to be used. square6 Definition gives square6 type of its return value square6 function's name (same rules as variable names) square6 names and types of its parameters square6 its statements (or body) ftype fname(parameterlist) { body of function } square6 If type omitted an int type is assumed. square6 If no return type is desired the term void should be used. square6 If parameter list is empty the term void should be used. square6 The body should have a
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: should have a return statement where the type matches the return type specified. s The fname must be unique. s A function can NOT be defined inside another one. Simple example function definition: void error_msg(void) { printf("This "); printf("is Bad Input\n"); return; } s function name = "error_msg" s return type = nothing s list of parameters = empty s body has only three statements 3 Calling (executing) a function: s general form: s function-name(any arguments) s as a statement: s printf("Hello,"); s or as an expression in assignment: s ch = scanf(“%d%d%d,&a,&b,&c); Examples s parameter passing example s return value example s function calling function example...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

04FunctionsLarge - should have a return statement where the...

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

View Full Document
Ask a homework question - tutors are online