12  12 1017

I´m goint to teach how to create a function in c++

First of all you have to choose which type of function you want.

Void = to return nothing.

Int = to return a integer number.

double = to return a decimal number.

bool = to return true or false

string = to return letters.

etc etc.

Well now that you know the types of functions you will have to select the  type you want for your variables which are pretty much the same.

Now, the syntax to do a function is:

type nameoffunction(variables, parameters)




Let´s say, we want to create a function which make the sum of two integer numbers

int sumnum(int x, int y)


     int c;

     c = x + y;

     return c;



Hope you understand how to create a function, it is really easy and don´t be afraid to create them because it will save a lot of coding and your int main() will be a lot shorter.


Hope you understand so i can get my two points!


CC BY 4.0 #mastery12 by Juan Carlos is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.