Explain functions

Apr 8, 2013 at 6:49pm
Can anyone explain functions to me? I need to write a 3 function program that calculates distance and slope, I am also using a bool function so that I can tell if the slope is infinite.

Thanks!
Apr 8, 2013 at 7:28pm
It's a broad subject. Too broad to be explained in a 3-line forum post.

Check out this tutorial instead:
http://cplusplus.com/doc/tutorial/functions/
Apr 8, 2013 at 8:46pm
...but basically they are blocks of code that can be executed, and they can have a 'return' statement (unless the function is 'void') that allows them to return data back to whatever called them.
Last edited on Apr 8, 2013 at 9:10pm
Apr 8, 2013 at 9:02pm
closed account (Dy7SLyTq)
they dont have to have a return statement and void can have one
Apr 8, 2013 at 9:12pm
I didn't say they had to have a return statement, and void functions cannot return any values.
Apr 8, 2013 at 9:15pm
closed account (Dy7SLyTq)
didnt say that. i said they can have a return statement
Apr 8, 2013 at 10:23pm
Can you give an example of a regular function and a boolean function?
Apr 8, 2013 at 10:34pm
What is a boolean function? As far as I know all functions are regular functions.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void f() //regular function
{
    cout << "Hello, world!" << endl;
}

int g(int a, int b) //regular function
{
    return 7*a + b;
}

bool h(int x, int y, int z) //regular function
{
    return x == 7*y && 7*x = z;
}
Last edited on Apr 8, 2013 at 10:35pm
Apr 8, 2013 at 11:45pm
A boolean function is a function that returns a boolean datatype.
ie:
1
2
3
4
5
6
7
8
9
10
void f(){//Returns no values

}
int f(){//returns integers


}
bool f(){//returns boolean datatype (boolean function)

}
Apr 8, 2013 at 11:50pm
All three function are normal functions. There is no such thing as a "boolean function" or "void function".
Apr 9, 2013 at 4:01pm
It's a matter of english syntax.
If someone said to me 'boolean function', I would know they were talking about a function that returns a boolean datatype.
Sure maybe it's not the right way to say it by your standards, but really, who gives a shit.
Apr 9, 2013 at 4:10pm
I stand corrected:
1
2
3
4
5
struct MyClass
{
    operator bool(); //boolean function
    bool f(); //normal function
};
Apr 9, 2013 at 4:20pm
L B, isn't that more usually called a "boolean conversion operator", or even a "boolean operator"?

That's a genuine question - I don't claim to know the widespread terminology for it.
Apr 9, 2013 at 4:23pm
I was being sarcastic ;) I think they're called type cast operators.
Apr 9, 2013 at 5:28pm
:P
Topic archived. No new replies allowed.