capypad
0 day streak
cpp / beginner
Snippet

Simple Function Definition

Functions help organize code into reusable blocks. They can take parameters and return values.

snippet.cpp
cpp
1
2
3
4
5
int add(int a, int b) {
return a + b;
}
 
int result = add(10, 5);
Breakdown
1
int add(int a, int b)
Defines a function that returns an int and takes two int parameters.
2
return a + b;
Sends the sum of a and b back to the caller.