1

From what I have learned, there is a difference between a function and a procedure. I know that a function returns a value whereas a procedure just executes commands one after the other. Today on the other hand, my professor stated that we can also use a procedure to return a value in a C program. I'm pretty sure that it is not possible. I also checked on the internet and read that a procedure just executes a command and a function executes and returns a value. I may be mistaken. If anyone can please tell me if I have the correct understanding , it would be a big help. Thank you !

Module
  • 250
  • 2
  • 13
  • 2
    C doesn't have procedures, only functions. The closest thing to a procedure in C would be a void function. Pascal OTOH has procedures and functions. – Paul R Nov 03 '14 at 17:16
  • http://stackoverflow.com/questions/721090/what-is-the-difference-between-a-function-and-a-procedure – Gopi Nov 03 '14 at 17:17

1 Answers1

2

There is no such a notion as procedure in C.

And what is written in the comments to my post is totally wrong and logically inconsistent because at first the notion of procedure itself shall be defined that it can be discussed. Different languages have different definitions of procedures, parameter passings and variable visibilities.

Moreover this statement of your professor clear demonstrates that his statement is false. It is false because at first he shall define the notion of proocedure. You may have your own notion of procedure where a procedure may not return a value while the professor may have his own notion of procedure.

So this statement has no sense.

C has no procedures.

The question could be formulated for example the following way: Does C have a construction that resembles procedures in Pascal or in Cobol. In this case you could discuss how a similar construction should look in C whether it shall have return type void, whether its parameters must be pointers or the construction shall deal only with global variables instead of parameters and so on.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • 2
    `void foo(int x)` probably meets most definitions of procedure. – William Pursell Nov 03 '14 at 17:16
  • A void function in C is almost the equivalent of a procedure in C. That's what I know. – Module Nov 03 '14 at 17:17
  • 1
    @William Pursell It is totally wrong. In C there is no procedures. So you should name the language that has notion of procedure and according to which void foo( int x ) can be considered as procedure. For example as far as i know in many languages procedures are defined such a way that oarameters are passed by references. – Vlad from Moscow Nov 03 '14 at 17:19
  • 1
    The fact that the C standard does not define "procedure" does not mean that there is no such in the language. It just means the standard does not name them such. The reason it avoids such language is obvious with a bit of thought: Doing so would draw a distinction which complicates the standard and provides no benefits. – Deduplicator Nov 03 '14 at 17:28
  • 1
    @Deduplicator You have a serious problem with the logic. "The fact that the C standard does not define "procedure" means that C has no procedures and nothing more. If you are going to speak about procedures you have to point out the definition of procedure in some language where this notion exists that the discussion would have some sense. – Vlad from Moscow Nov 03 '14 at 17:31
  • 1
    @Vlad: Whenever the standard does not define a term, we have to fall back on technical english and finally on coloquial english. If we did not do so, the standard could be some orders of magnitude bigger and would still not even start describing C. And the term procedure is quite distinctly known as a technical term. – Deduplicator Nov 03 '14 at 17:34
  • I totally agree with Vlad. There is no need to "pollute" terminology with procedures or maybe even subroutines in the context of C language, because there are simply no such concepts herein. – Grzegorz Szpetkowski Feb 11 '15 at 20:23