← Back to C Course | Chapter 5: Functions | Lesson 2 of 8

C Function Parameters

What are Parameters?

Parameters are the variables listed in a function's definition that receive external data when the function is called, letting the same function body operate on different values each time it runs.

Example: What are Parameters?

c
#include <stdio.h>
void greet(char name) {
	printf("Hello, %c", name);
}
int main() {
	greet('J');
	return 0;
}

Single Parameter

A function with a single parameter -- like void greet(char name) -- requires the caller to pass exactly one argument whose type matches that parameter's declared type, or the compiler will flag a mismatch.

Example: Single Parameter

c
#include <stdio.h>
void greet(char name) {
	printf("Hello, %c", name);
}
int main() {
	greet('A');
	return 0;
}

Multiple Parameters

Separating several parameters with commas, like int add(int a, int b), lets a function accept multiple pieces of input at once, all available inside the function body under their own local names.

Example: Multiple Parameters

c
#include <stdio.h>
int add(int a, int b) {
	return a + b;
}
int main() {
	printf("%d", add(3, 4));
	return 0;
}

Parameter Types

C parameters can be declared as any valid data type -- int, float, double, char, and beyond -- and the arguments you supply on a call must line up with those types and their order, since C matches arguments positionally, not by name.

Example: Parameter Types

c
#include <stdio.h>
void showInfo(int age, float height, char grade) {
	printf("%d %.1f %c", age, height, grade);
}
int main() {
	showInfo(20, 5.9f, 'A');
	return 0;
}

Actual vs. Formal Arguments

The parameters listed in a function's own definition are called formal arguments, while the actual values or variables you pass in when calling it are called actual arguments -- the distinction matters when discussing how data flows into a function.

Example: Actual vs. Formal Arguments

c
#include <stdio.h>
int add(int a, int b) {
	return a + b;
}
int main() {
	int x = 3, y = 4;
	printf("%d", add(x, y));
	return 0;
}
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.