explian a function in c++ (I'm a beginner)

Basically, it is a block of code identifies with a name.

Not completely.

Every functions has a domain and a co-domain and its definition.

The domain is the valid range of numbers that can be accepted.
The co-domain is the valid range of numbers that the function can …

## All 5 Replies

Basically, it is a block of code identifies with a name.

Basically, it is a block of code identifies with a name.

Not completely.

Every functions has a domain and a co-domain and its definition.

The domain is the valid range of numbers that can be accepted.
The co-domain is the valid range of numbers that the function can map to.

The definition of a function gives some explicit way to convert the input into an output.

For example, consider the function F: R - >R, where F(x) = x*x.
The function domain is R( all real numbers), the function co-domain
is R(all-real numbers) and its definition is F(x) = x*x.

Now in code its very similar :

``int F(x){ return x*x; };``

Now the domain is implicitly stated as all real numbers. So we do not check if x is an imaginary numbers( that and we can't anyways).
The co-domain is all real number and is implicitly stated by the return type of the function, int. The definition is x*x, which is in the
body of the function.

So that is a function.
It has a domain, the valid range of numbers the function can accept.
It has a co-domain, the valid ranges of numbers the function can map to or "spit out".
It has its rule, or its definition.

Not completely.

Every functions has a domain and a co-domain and its definition.

The domain is the valid range of numbers that can be accepted.
The co-domain is the valid range of numbers that the function can map to.

The definition of a function gives some explicit way to convert the input into an output.

For example, consider the function F: R - >R, where F(x) = x*x.
The function domain is R( all real numbers), the function co-domain
is R(all-real numbers) and its definition is F(x) = x*x.

Now in code its very similar :

``int F(x){ return x*x; };``

Now the domain is implicitly stated as all real numbers. So we do not check if x is an imaginary numbers( that and we can't anyways).
The co-domain is all real number and is implicitly stated by the return type of the function, int. The definition is x*x, which is in the
body of the function.

So that is a function.
It has a domain, the valid range of numbers the function can accept.
It has a co-domain, the valid ranges of numbers the function can map to or "spit out".
It has its rule, or its definition.

Not sure if you were purposely trying to confuse him, but in begginers terms a function is a block of code that is called from main(which is also a function) or from another function to execute some code. Functions can accept arguments like has been already stated, but if your just learning, first learn how to call a function before you get fancy with one.

firstPerson's definition is more like one that might be used in a formal mathematical setting. Check out the second paragraph of http://en.wikipedia.org/wiki/Functional_programming for a comparison of the two definitions. I'm sure we could argue about the semantics of what constitutes a function (like "is a void function really a function by one definition or the other?") but I think WaltP offered the best approach as it seems the OP was just looking for basic info...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.