👆ClickKnowledge and Action Integration GESP> Click the top right corner “···” > Set as a star 🌟
Hello everyone, I am Teacher Huang. I have worked in several large state-owned technology companies and have many years of practical experience in C/C++, having developed electronic terminal products with millions of users. Currently, I am an amateur lecturer for children’s C++ programming, after all, CSP also claims to benon-professional.😁
I have completed the column of “GESP Level 1 Survival Series“, the column of “GESP Level 2 Programming Survival – Character Graphics“, and the column of “GESP Level 2 Programming Survival – Brute Force Enumeration“ for everyone’s reference.
Now the column of “GESP Level 3 Programming Series“ is basically complete, and I am preparing to share articles related to Level 4, and will continue to share relevant practical experiences, learning and progressing together with the students.🚀


Selected Past Articles
GESP Certification Level | Programming Problem Submission Status AC, WA, TLE… All Black Language Bleached!
GESP Level 3 C++ Programming Problem Summary: 2025.11.07
GESP Certification Level C++ Level 2 Survival Notes – Nested Enumeration
GESP Certification Level C++ Level 2 Survival Notes – Character Graphics
GESP Certification Level C++ Level 1 Survival Problem Series Notes
Welcome to follow our public account, to learn and progress together like👍 | share🌏 | recommend♥️ | forward🔥 | comment🐳
The GESP Level 4 Programming Exam builds upon the GESP Level 3 Programming, adding applications of two-dimensional arrays, functions and exceptions, structures and pointers, file operations, bubble, selection, and insertion sorting algorithms (sort), and recursive algorithms (recursive functions). The content in parentheses may be beyond the syllabus, but learning it early is beneficial!
Why is this article called Introduction to Custom Functions? Because when we teach programming to elementary school students, it can be quite challenging to explain what a function is! Many so-called functions, such as swap, min, max, abs, etc., are encountered and used before GESP Levels 1, 2, and 3.
The GESP Level 2 syllabus clearly requires us to master the use of some mathematical functions and random functions, and we usually let the children remember one thing: C++ functions are like various shapes and colors of building blocks; you can use the blocks provided by the system (system functions) to combine them and build your own program!
↑sqrt function declaration↑
Actually, there is no need to introduce such detailed terminology about functions; we just need to master the rules and principles as follows:

6×6=36, and after processing with sqrt, it outputs 6, but the return type is all double, just remember that. Further explanation gets closer to the truth of functions as shown in the figure below, but remember the principle of not discussing three things: if you don’t understand, don’t talk about it! Recommended: Slow is Fast: Reflections on Learning C++ Programming

However, our GESP C++ Level 3 exam questions tend to favor some out-of-syllabus custom functions and objective questions regarding function parameters, and even the official programming problem solutions often feature custom functions. Therefore, before we complete the Level 3 series articles and start the Level 4 series articles, we will first share a series of content on function definitions, declarations, and calls!
The First Custom Function in C++
01
From the first day of learning C++ programming, I say you have already been defining functions. What? All teachers will tell students: the main function is the main function, the only entry point for C++ programming, and there can only be one main function in C++ programming. That’s right! Now let’s take a closer look at the main function that accompanies us day and night, what are the details we usually overlook!
main image one
main image two
The above two images present different forms of the main function.
First, we need to clarify that the main function does have parameters, but during the exam, we do not need to consider these parameters; the writing of the main function shown in image one is sufficient to meet the requirements.
Secondly, for different programming problems, the code content written in the main function will inevitably differ from the problem-solving ideas; is this true? Please seriously recall the programming problems you have done, is this indeed the case? In terms of the text in the image, that is the code for different programming problems must have different main function bodies.
From this, we can infer that we can also create new “building blocks” (custom functions) ourselves to complete more complex problems. After all, even the most complex building block puzzles are made up of simple basic building blocks.
Custom Functions
02
What is a function? Mathematically defined: first, a function must have a name. The most common name is “f“, but it can also have other names; here we use “f”:
We place the input value in the parentheses following the function name:
So f(x) means the function is called “f“, and “x” is the input value
The operation performed by the function on the input value:
f(x) = x2 shows that the function “f” takes the input value “x” and squares it.
We now only need to remember that programming functions are different from mathematical functions. To understand mathematical functions, please refer to:
https://www.shuxuele.com/sets/function.html
Now the following diagram explains the syntax of custom functions:
Here are a few examples of custom functions, I hope students understand!!!
1. Define first, then call
#include <bits/stdc++.h>using namespace std;// 1 Function definitionint add(int a, int b) { return a + b;}int main() { // 2 Function call int ans = add(12,13); cout<<ans<<endl; return 0;}
2. Declare first, then call, then define
#include <bits/stdc++.h>using namespace std;// 1 Function declaration (function prototype)int add(int a, int b);int main() { // 2 Function call int ans = add(12,13); cout<<ans<<endl; return 0;}// 3 Function definitionint add(int a, int b) { return a + b;}
Functions to Memorize for Levels 3 and 4
03
1. Prime Number Check
bool isprime(long long x){ for(long long i=2; i<=sqrt(x);i++){ if(x%i == 0) return false; } return x>=2;}
2. Palindrome Check
bool ishw(long long x){ long long y=0,t=x; while(t){ y = y*10 + t%10; t = t/10; } return x==y;}
3. Palindrome String Check
bool ishw(string s){ int len=s.size(); for(int i=0,j=len-1;i<len;i++,j--){ if(s[i]!=s[j]) return false; } return true;}
4. Count Digits
int ssw(long long x){ int res = 0; do{ res++; x=x/10; cout<<x<<endl; }while(x); return res;}
5. Sum of Digits
int swh(long long x){ int res = 0; while(x){ res += x%10; x /= 10; } return res;}
What exactly is a function? If you still don’t understand, look here!
In simple terms, it is a block of code that has been rigorously tested and guaranteed to be error-free. As users, we don’t need to care about how it works inside; we just need to know how to call it. But if you want to write this function, you need to clarify what inputs it takes, what outputs it produces, and how to transform the inputs into outputs. For example, the following real-life example:

Using a rice cooker to cook rice is very simple: add some water and rice, plug it in, press the cook button, and wait for it to do its job, and delicious rice is ready! But if you are the manufacturer of the rice cooker, it becomes much more complicated; you need to understand materials, processes, packaging, and also know how to design hardware and software, and write the manual, all aspects must be clear.
Additionally, I recommend parents read What is Programming to understand programming, which includes the teacher’s WeChat contact information! Providing systematic learning services and assessment services for Levels 1, 2, and 3.