⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽

User Defined Functions

Computer Programming C++ / Functions

A function is a named section of code that performs a task. The terms function and method are often used interchangeably, but let's look at the difference.

Let's look at a simple function.

One more thing before moving on to parameters. You may have noticed that if you put your function below your main() function, it doesn't compile. This video will explain why.

Review Questions

The following are examples of questions similar to what you can expect to see on the next exam.

Hover over a question to show the answer.
  1. What is the difference between a method and a function? A method is a function that is inside of a class.
  2. What is the syntax for a function? (what are the parts?) return type, name, [parameters], and the body (parameters are optional)
  3. What is a function prototype? A declaration of a function that specifies the function's name and signature.
  4. How would you write a function that doesn't return anything? Make the return type void.
⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽
© Ryan Appel