Lesson 75 +10 XP

Function Parameters

Function Parameters

Functions get data through parameters: values you pass in when you call them.

Defining with parameters

void greet(char name[]) {
    printf("Hello %s!\n", name);
}

The parameter name is a variable the function can use.

Calling with arguments

greet("Ada");
greet("Grace");

Output: Hello Ada! then Hello Grace!

Multiple parameters

void show(int num, char label[]) {
    printf("%s: %d\n", label, num);
}

show(42, "answer");

Parameter vs argument

  • Parameter - the name used inside the definition.
  • Argument - the value passed when you call.

TL;DR

  • Parameters are the function's inputs.
  • List them in the parentheses of the definition.
  • Arguments match the parameters' order and types.
  • A function can have many parameters.