Differences between `function`, `method` & `procedure`

In Java, we may often listen method, but in C, we always call such things function. So what's the differece?

Function

In C, function is a really common thing. It may look like int add(int a, int b), which looks very similar to method, however, they are totally different.

  1. function is an individual function, not relevant to the object. It transfers data explicitly. So it appears in procedure-oriented programming languages (e.g. C).
  2. Usually, function has return value. In other words, return type cannot be void. If return is void, we usually call it procedure.
  3. function is always like static mathod, can be call directly.

Method

If mention method, maybe people will first think that Java and C#. That's right.

  1. method has strong relationship to object. So we may find method in object-oriented programming languages.
  2. method must exist under a class.
  3. method is called by object only.
  4. method processes object's data, so the way of data transfering method uses is implicit.
  5. method can be static and dynamic.

Procedure

  1. Refer: Function 3.

Post a Comment

Your email is never shared. Required fields are marked *

*
*