0

I read many many articles about difference between function and procedure but there is something I'm in doubt about.

Do we call following statement a function or a procedure in terminology?

void f() { return; }

Some articles says function returns value but procedure does not.

Some other article says if a function returns one value called function but if it returns more than one value it called procedure.

Hamed Kamrava
  • 12,359
  • 34
  • 87
  • 125
  • 2
    It really depends on the language, and I don't think procedure is a very useful term in either C or C++. – juanchopanza Dec 18 '14 at 14:58
  • 1
    In C and C-like languages there are no procedures, only functions. – Some programmer dude Dec 18 '14 at 14:59
  • 2
    C++ uses the term 'function' regardless of whether it returns anything or not. It also doesn't use the term `method` for member functions. That said, I think that if you used those terms it wouldn't cause confusion - just don't expect them to be used by others. – Michael Burr Dec 18 '14 at 14:59
  • @BennoZeeman I've read that thread before. I think my question is different – Hamed Kamrava Dec 18 '14 at 15:03
  • Where did you find the distinction in the last paragraph? It sounds very odd. – molbdnilo Dec 18 '14 at 15:05
  • @molbdnilo http://www.geekinterview.com/question_details/4662 – Hamed Kamrava Dec 18 '14 at 15:07
  • @HamedKamrava That's a "PL/SQL" question (and answer). Programming terminology is often very language-specific. – molbdnilo Dec 18 '14 at 15:14
  • @HamedKamrava [It does](http://stackoverflow.com/a/721132/2703418). A few people mention the language specificness of this terminology. A procedure is just a function C. The distinction is gone. – bzeaman Dec 18 '14 at 15:28

6 Answers6

2

In the standard terminology of C and C++, no. It's a function whether or not it returns anything, or even if it doesn't return.

In more general computing vocabulary, and the terminology of other programming languages, it might be called a "procedure" or a "subroutine" (and perhaps a few other terms) if it doesn't return a value.

Mike Seymour
  • 249,747
  • 28
  • 448
  • 644
1

A procedure is a function that do not return a result!

mortada
  • 23
  • 6
  • I agree and with all the posts that point out that C and C++ both only refer to functions not procedures. Many authors tend to differentiate that functions return values and procedures have side-effects. I think that distinction is consistent with the way 'function' is normally used in mathematics and 'procedure' as a set of instructions to perform an action. Think of (say) a building evacuation procedure. I'm not so sure the distinction is hugely useful in programming as many candidates have side-effects and return values. What do we call them? – Persixty Dec 18 '14 at 15:15
  • What about a function which sometimes returns a result? (j/k) – MSalters Dec 18 '14 at 15:54
  • are you talking about idempotent functions Mr. Dany Allen? – mortada Dec 18 '14 at 15:56
1

There is no such term as procedure in C and C++ languages. So relative to C and C++ languages your question has no sense. In any other languages the definition of the term procedure can vary.

In C and C++ statement

void f() { return; }

is a function definition.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • I know there is no such term as procedure in C/C++. But I mean do we call it `function` or `procedure` in concept ? – Hamed Kamrava Dec 18 '14 at 15:10
  • 3
    @Hamed Kamrava As there is no such a concept as procedure in C/C++ then there is no sense to speak about this term in the frames of C/C++. As I wrote in my posty the concept can vary in other languages where it is defined. – Vlad from Moscow Dec 18 '14 at 15:12
1

As Mike annd Grzegorz says, from C Standard point of view there is no difference, but the function term is used by convention.

In other programming language (e.g. basic) that distinction is commonly used depending if return or not a value that function.

As final note: in the C Programming Language book (official C programming language book) from Dennis Ritchie (C creator) the term function is used independently if returns or not a value and that's one of the reason that the term is used indistinctly.

PlainOldProgrammer
  • 2,725
  • 5
  • 22
  • 30
  • 1
    No, the official C language document is ISO/IEC 9899. _The C Programming Language_ by **Kernighan** and Ritchie is not official, although influential. – MSalters Dec 18 '14 at 15:53
  • 1
    Well, maybe I've been ambiguous. When I said that is the official C programming language book I'm referring that is the de facto standard for learn C, and not a specification or C Language document. – PlainOldProgrammer Dec 18 '14 at 16:46
0

From the C Standard point of view there is no distinction between functions and procedures (like in e.g. Pascal) or subroutines (like in e.g. Fortran). Both types (i.e. returning void and non-void) are simply named as functions. I believe that C++ just follows this way.

Grzegorz Szpetkowski
  • 36,988
  • 6
  • 90
  • 137
0

There are various terminologies that means the same in various different languages. Like function used in structured language like c, Method's used in java, procedure, function both used in Scala.

In reality, Procedure is a function really but that doesn't return anything and in C we still refer to it as function.

SMA
  • 36,381
  • 8
  • 49
  • 73