Difference between “operator” and "statement" in programming [closed]

To describe the same language units in computer programs I came across words such as: "operator" and "statement". Also my dictionary gives these words as synonyms.

Question: what is the difference and what is better to use in programming? Or is it not important? Thanks in advance!


Solution 1:

It's difficult to be 100% sure without more information from you, but either you or your sources are incorrect. An "operator" is never the same as a statement.

An operator is a symbol that acts like a function. In most (all?) languages, it can operate on one, two, or three values. This is not unique to computer science; the idea of an operator comes from mathematics, where an operator represents a mapping from one space to another.

On the other hand, a statement is the smallest unit of an imperative language that expresses some action to be taken out.

An operator without values doesn't do anything, so an operator cannot be a statement.

An operator with the appropriate number of values is known as an expression, but still may not be a statement, if it doesn't do anything.

For instance

i++;

is a statement, because it assigns a value to i. However

i + j;

is not a statement as it doesn't perform an action. Some languages would flag this as an error. Other languages will remove this during compilations. Others still will perform the operation and then discard the value.