← All lectures

Lecture 18 · 30 min

Types of Functions

Four function shapes by return type and arguments, pass-by-value, and the scope/lifetime of local, global, and static variables.

4 function shapesPass by valueLocal vs global vs static
Slide 1 / 15

The four function shapes

Every function you write falls into one of four categories based on:

  • Does it return a value? (yes/no)
  • Does it take parameters? (yes/no)

All four are useful in different situations.

ShapeReturn TypeParametersExample
1voidNonevoid printMenu()
2voidHas parametersvoid print(int x)
3Non-voidNoneint readScore()
4Non-voidHas parametersfloat sum(float a, float b)
← / → navigateF fullscreenEsc exit⌘K search