C & C++ fundamentals / 12
Declaring and calling functions
Move repeated work into a function and call it from main instead of copying the same statements.
We already know one function: int main(). So far, we have put most of our code there. As a program grows, however, we may need to perform the same work more than once. Copying and pasting the same statements makes the code harder to maintain.
Instead, we can declare another function. Here is a simple example using void test():
#include <stdio.h>
void test()
{
printf("Hello");
}
int main()
{
test();
return 0;
}
The program defines a function named test. Inside main, the call test(); runs the statements inside that function, printing Hello.
This lets us give a reusable block of work a name and call it whenever we need it.
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