Answer the question
In order to leave comments, you need to log in
What is the difference between functions, procedures and operators (on the example of FreePascal)?
Literature: Stolyarov, "Programming, an introduction to the profession"
Procedures:
Operators:
Functions:
An example of using this all:
Answer the question
In order to leave comments, you need to log in
Functions and procedures are almost the same thing. The only difference is that a function returns a value, while a procedure does not. Obviously, a function can be used like a procedure by simply ignoring the return value. Therefore, in other languages, such a concept as a procedure is usually not even introduced. And in C-like languages, where a function must have a return type, the void type is used, which also kind of makes the function a procedure.
Speaking of functions or procedures, the emphasis is on the calling mechanism itself - the pointer to the current execution location is placed on the stack, control is transferred to the function, and when it ends, the pointer is restored from the stack and program execution continues from the same place. Thus, two points are meant: 1) the function call itself 2) the location of the function body in another memory location. That is, a function is essentially a subroutine.
The operator is, in fact, a separate independent instruction. Usually they can be interchanged at the same nesting level, and this will not add syntax errors. However, the instruction itself can be not only simple, but also complex, compound. For example, a whole block, or a conditional statement, or a loop. Thus, an operator can contain other operators. This must be understood in order not to get confused in the terminology. Speaking of operators, the emphasis is on the fact that code is a sequence of instructions that are executed one after another. A function call (its call) is also an operator in the sense that it is a separate instruction.
Procedures do not return a result, functions do.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question