Skip to main content
Logo image

Section 12.1 Single Functions

You have already seen the use of a function in C, namely the main() function! We donโ€™t tend to think of main() as a function but it is indeed one.
Functions allow you to group a bunch of statements together that can be called upon to execute at any point in your code. Depending on the type of function you write, you can pass information to the function and it can return information back to you.
Here is a first example of a function in C:

If you cannot see this codecast, please click here.

Aside: Video Description.

Check Your Understanding Check Your Understanding

2.

Write a function divide() that takes two floats as arguments and returns a float, namely the first number divided by the second. Obviously, you shouldnโ€™t be dividing by zero...
You may assume that your function is not called with such input.

admin.....open in new window

When your program performs correctly youโ€™ll be given a keyword to enter in Canvas.