Hello, thank you for taking a moment to review my first thread. It is nice to meet you all. I apologize if this is below any of you, but I would like to receive clarification on Functions in C++. I have a laptop running linux mint 17, using the CODE::BLOCKS IDE. From what I am learning, functions are broken down into this format.
1 2 3 4
<return type> name (arguments to the function)
{
return expression;
}
I am struggling to comprehend what it means to have "The arguments to a function passed to the function to be used as input information. The return value is a value that the function returns."
That is a couple of statements taken directly from a book on C++. I have also read the tutorial on this site regarding functions. I am still having problems understanding. If anyone could clarify the topic of functions and explain it in simpler terms, I would be grateful.
I'll come up with a simple example of a function so you can see what the purpose are.
Let's say I want to write a function that multiplies an integer by two. This is what the function would look like:
1 2 3 4 5 6 7 8 9 10 11 12 13
int twotimes( int a ) //a is the number I want to multiply by two;
{
int b;
b = 2*a;
return b;
}
int main()
{
int c, d;
c = 5; //Some arbitrary value for c
d = twotimes(c); //This sets d equal to c times 2
}
Now obviously this example isn't something you would do in practice, because you can just type d = 2*c in your code. But it demonstrates how a function is written and called in the main program.