954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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

naveedmahar
Newbie Poster
3 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 
WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

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

kbshibukumar
Junior Poster in Training
65 posts since Jan 2009
Reputation Points: 12
Solved Threads: 8
 
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.

firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608
 

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.

LevyDee
Posting Whiz in Training
260 posts since Mar 2010
Reputation Points: 13
Solved Threads: 25
 

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...

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: