Solved

Difference between the function and procedure

Posted on 2004-10-15
11
33,479 Views
Last Modified: 2011-08-18
Hi..

I have come across the question of Difference between function and procedure a lot and every time heard the same definiation that Fucntion Returns Value and procedure doesn't is the only difference (other are derived from it if any).

So Just want ot know what is correct. Though I believe that function and procedure are nto different but a different name given by different programming languages to same think and sometime used as I said above.

Any idea

VIkasumit
0
Comment
Question by:VIkasumit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 20

Accepted Solution

by:
Venabili earned 25 total points
ID: 12316782
Hi VIkasumit,

It depends on the language. Usually the idea is exactly this:
function - returns result
procedure - does not return result

Java uses the name method for both for example :)

Venabili
0
 

Assisted Solution

by:tarandeep
tarandeep earned 25 total points
ID: 12317808
Hi VIkasumit,

Both functions and procedures are a set of instructions that performs a specific task. The difference between the two is that a function *can* return a result value to the caller where as procedure *can not*.

Now, it is programming language dependent whether it provides support for functions or procedures or both.

For example:
Pascal provides support for both functions and procedures.
C provide support for functions, but a function can mimic a procedure by defining the return type as void.

...Tarandeep
0
 
LVL 15

Expert Comment

by:babuno5
ID: 12319237
hello,
well actually all the above stuff regarding function and procedure about returning values is all correct
but if u go deep then the meaning is different actually if a function is called then the control is passed to that function and returned with the returned statement that is must in a function .
well for a procedure it is just a refrence to that memory location execute that set of instructions and come back in this no control is passed to that procedure
one more difference is that a function is slower as compared to a procedure.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 101

Expert Comment

by:mlmcc
ID: 12319274
As stated above both functions and procedures are named blocks of code that can be used to perform a task such as calculate an average or read data from an input source.

The main difference is in the way they are used.  Both functions and procedures can return information.  A function returns a single object that is used immediately in the context of where the function was called while a procedure doesn't.  Function calls are used in an expression such as hyp = SQRT(a^2 + b^2) to find the length of  the hyopotenuse of a right triangle.

A procedure is called as a statement and can return information in one or more of its parameters.

READ(10, MyName,MyAddress)

mlmcc
0
 
LVL 4

Author Comment

by:VIkasumit
ID: 12319464
So, Every one jus answer feel that the function and procedure are different in sense that they return the value or not.

Well in that case I just want to introduce one more thing in it.....inline function now they doesn't return the value, nor they shift the control than work as statement...so inline function is a procedure?????


VIkasumit
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12320768
An inline function is neither a function nor a procedure.

It is when you take the code that would normally be in a function, and instead paste it directly where the function call would have been.  This is most commonly used when speed is an issue.  Instead of calling a function repeatedly from inside some kind of looping structure, you simply paste the code from the function directly into the looping structure (obviously some minor modifications are sometimes necessary in the code).  This speeds up the code since you don't have to invoke the function, pass the values, etc...

~IM
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12320795
Some languages allow you to declare an inline function and then the compiler does the conversion for you.  In others, you must do this process manually.

~IM
0
 
LVL 3

Expert Comment

by:aravindtj
ID: 12320903
hi,
 Inline function is a feature of OOP. It is handled depends upon the compiler. It is like macro functions and not exactly same.
 They are used for fast/atomic operations only. The compiler must support the inline functions.

Hope you understand.
all the best
0
 
LVL 4

Author Comment

by:VIkasumit
ID: 12321021
Well I thought enough talk has taken place about the Main question a it give me the genreal concept of what other thought of the Function and procedures....

I have summarize it as--
   Function : A name that define the behaviour/ or a collection of the statement that on complete execution return some value to the caller
   Procedure : Do every thing a function can but doesn't return any Data value (may be the control/flow is return)... to caller

And these defination depends on programming language...  you call a Computer or Desktop OR PC  in general they refer to one White Box at your desk and is our profession...

VIkasumit
0
 

Expert Comment

by:percuno
ID: 13844384
In every language I have ever used, if memory serves, both functions and procedures return values. Both functions and procedures can be passed values in most of them. Both functions and procedures can have their code dumped in-line into the calling program. There is no fundamental difference between them that even approaches universality, except that once, long ago, it was stated that functions should only perform mathematical transformations and procedures were not limited by this stylistic stricture. Basically, there is absolutely no difference between functions and procedures that can be stated as being even remotely universal; they have become, essentially, two words meaning the same thing.
0
 
LVL 4

Author Comment

by:VIkasumit
ID: 13844653
Hi,

It is good to see that some one has answer the question after that long. Well I do agree with you that their is not difference in them in general...

but Today the world has change a bit. Now there is no general concept remain it is only language based concept remain in this world ...So most of the answer that are above have that tendency in them...

So It is better not to take these things ahead...:)

VIkasumit
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question