C & C++ fundamentals / 13
Function parameters
Pass values into a function with typed parameters and understand what happens to those values.
Last time, we declared a function with void test(). Today, we will pass values into one by writing parameters inside the parentheses: void test(int num1, int num2).
The values supplied by the caller are assigned to parameters with the names and types we specify. Here, those parameter names are num1 and num2.
#include <stdio.h>
void test(int num1, int num2)
{
printf("%d %d",num1,num2);
}
int main()
{
int number1, number2;
scanf("%d %d",&number1,&number2);
test(number1, number2);
return 0;
}
The variables number1 and number2 are read in main, while the test function prints their supplied values. If we input 2 and 3, the parameters num1 and num2 receive 2 and 3. The same general idea applies to other parameter types.
Editorial correction: the original article stated that changing these parameters would also change
number1andnumber2inmain. That is not true for this code. Theintparameters are passed by value, so the function receives copies. Modifying them does not modify the caller's variables.
The next lesson concludes this introduction to functions.
Moved here from Tistory
I migrated this post from my Korean Tistory blog, I am Jason Lee, to this website and translated it into English. My writing and projects now live together in one place.
The original publication date, code examples, and screenshots are preserved. Editorial notes clarify known issues in the original material.
Original post on Tistory English edition · Aug 30, 2026