Tag Archives: #mastery12



Here is the youtube link to mastery12: https://www.youtube.com/watch?v=kNgEAiYSGkg

Functions in c++ are really important in order to do lots of repetitive stuff. Instead of writing down the code for a sum or something like that, you can just call a function that does that every time you want. Here is a simple example:


using namespace std;


int function1(int a, int b){

  int c;


  cout<<“c: “<<c<<endl;

  return 0;


int main(){

  int a,b;

  cout<<“give me a:”<<endl;


  cout<<“give me b:”<<endl;




Create fuctions

Para crear una funcion y las operaciones que se deben hacer por ejemplo ahy llamamos a la funcion suma con un rango de numeros para despues ya correr el programa.

Este video te explica mas claro sobre las funciones, se me hizo muy util, deberian de verlo https://www.youtube.com/watch?v=OaYDfOCsKtE

Creating Python functions

To create a function you have to give your function a name after the word “def” and then, in parenthesis, specify the variable you’re going to work with within that function. After that, you want to write what you want the program to do in return whenever you call that function. For example:

def hello(x):

       return “Hey there ” + x

And there you go. You’ve created a new function!

Mastery11 and Mastery12

12.Creating Python functions.

In order to call a function we have to create it first, in python there are basic functions like sum or division. However we can actually create our own.

first we have to write “def”, in order to define our function. Now we have to write the name of our function, in this case I’m calling it sum_numbers, because we’re going to sum these numbers. Now we write in parenthesis the variables that we want to use. Then we’ll write the action that our function will do, this time is adding x plus y. Finally, we have to write “return answer” so the function give us the answer of the addition that we did there.

11.Calling Python functions

Now to call this function, we have to give them the value of variables, in this case num1 and num 2. Now we have to write the function, sum_numbers, but instead of having x and y, the actual value; num1 and num2. So now the function will make the addition of num1 and num2, the answer to this addition will be the value of the_sum. Now we only have to print “the_sum” in order to actually see the solution of  num1 + num2.

mastery 11 y 12

Creating Functions in C++ (Mastery 12)

Here is a link to my video on how to create a function in C++:


Hope you found this video helpful!


H0yos Adventures 2015-04-07 22:22:56

hi there i made my first video about calling and creating functions. its a really easy code but it explains how to create a function and calling it in the  main function,  


here is the link for the video tutorial: 


here is the link for the code in git hub 


Mastery 12

I made a video for mastery 12!:


Mastery 12

Creating functions in C++


Functions allow to structure programs in segments of code to perform individual tasks.

In C++, a function is a group of statements that is given a name, and which can be called from some point of the program. The most common syntax to define a function is:

type name ( parameter1, parameter2, ...) { statements }

– type is the type of the value returned by the function.
– name is the identifier by which the function can be called.
– parameters (as many as needed): Each parameter consists of a type followed by an identifier, with each parameter being separated from the next by a comma. Each parameter looks very much like a regular variable declaration (for example:int x), and in fact acts within the function as a regular variable which is local to the function. The purpose of parameters is to allow passing arguments to the function from the location where it is called from.
– statements is the function’s body. It is a block of statements surrounded by braces { } that specify what the function actually does.



// function example
using namespace std;

int subtraction (int a, int b)
  int r;
  return r;

int main ()
  int x=5, y=3, z;
  z = subtraction (7,2);
  cout << "The first result is " << z << 'n';
  cout << "The second result is " << subtraction (7,2) << 'n';
  cout << "The third result is " << subtraction (x,y) << 'n';
  z= 4 + subtraction (x,y);
  cout << "The fourth result is " << z << 'n';
The first result is 5
The second result is 5
The third result is 2
The fourth result is 6


Functions are really useful when you want to structure and organize a program. Stating functions is really easy because you only need to write the type of value that the function will return and between “()” you declare the parameters.

Here you can see a picture of an example:

In this link you can find a pp that I did to explain how to create functions with detail: https://drive.google.com/file/d/0B-NM4ghaDXBvT0hGVmtHM3FDMms/view?usp=sharing

Also, here you can find my c++ code: https://drive.google.com/file/d/0B-NM4ghaDXBvVVI2Nmw3bUNVb0U/view?usp=sharing

Finally, in this link I found useful information to understand this, and I used that information to do my pp: http://www.cplusplus.com/doc/tutorial/functions/