"A function returns a value whereas a subroutine does not. A function should not change the values of actual arguments whereas a subroutine could change them. "
what if i pass the arguments in the function by reference then they can be changed. Doesnt this contradict the above statement
That statement isn't true: in C++ you always have functions, some could have no return type ( void ), some could have arguments by pointer or reference (and modify the values of arguments) and some could have both
That phrase quoted by the original poster is in a JAVA faq section not C++.
can any JAVA programmers here confirm the validity of that particular statement then or as is mst likely the case - the faq is talking crap?
The quote is talking about functions and subroutines, which suggests it's talking about them from the computer science perspective, and not from that of a particular language.
The distinction in Function/Subroutine comes from Fortran II (maybe others) circa 1960. In Fortran you had to specify that a return value was required by declaring the subprogram to be a FUNCTION. SUBROUTINES could not return a value via the return statement. Both could alter arguments.
C (circa 1970) removed the distinction. All subprograms were functions and by default, return an 'int', This later was altered with the inclusion of 'void' and made subprograms smell and feel that Fortran SUBROUTINES. C++ adopted the convention.
In Ada there is a clear distinction betwen FUNCTIONS and SUBROUTINES. In FUNCTIONS you can not alter arguments (although you can if you use wrappers). In SUBROUTINES you can modify arguments but you can not return values.
Other languages do other things. For C/C++ any FUNCTION can be made a SUBROUTINE by declaring the return value to be 'void'.
Subroutine also describes a callable section of code with no notion of parameters as seen in Macro Assembers, COBOL and BASIC. They use global variables.