Arithmetic Statements Interview Questions


What is Arithmetic expression?

An arithmetic expression is a user-defined formula that performs arithmetic calculations. These are combinations of variables and numbers separated by arithmetic operators.

What are the Arithmetic expression precedence rules?

The evaluation order of operators is -

  • Expressions within parentheses ( ).
  • Unary operator +, -.
  • Exponentiation **
  • Multiplication and division *, /.
  • Binary addition and subtraction +, -.

ADD Statement -

What is the use of ADD statement?

ADD statement performs addition operations.

What are the different formats of ADD statement?

ADD statement is divided into below types based on their usage -

  • Simple ADD statement.
  • ADD with ON SIZE ERROR (Error handling).
  • ADD with GIVING.
  • ADD with CORRESPONDING.

What is the significance of the GIVING in ADD statement?

GIVING phrase specifies that the output variables are used to store the result and are not part of the inputs.

SUBTRACT Statement -

What is the use of SUBTRACT statement?

SUBTRACT statement performs subtract operations.

What are the different formats of SUBTRACT statement?

SUBTRACT statement has below formats based on their usage -

  • Simple SUBTRACT statement.
  • SUBTRACT with GIVING.
  • SUBTRACT with ON SIZE ERROR (Error handling).
  • SUBTRACT with CORRESPONDING.

What is the significance of the GIVING in SUBTRACT statement?

GIVING phrase is used when the output variables only used to store the result and not part of the inputs.

MULTIPLY Statement -

What is the use of MULTIPLY statement?

MULTIPLY statement performs multiplication operations.

What are the different formats of MULTIPLY statement?

MULTIPLY statement has three different formats on their usage -

  • Simple MULTIPLY statement.
  • MULTIPLY with ON SIZE ERROR (Error handling).
  • MULTIPLY with GIVING.

What is the significance of the GIVING in MULTIPLY statement?

GIVING phrase is used when the output variables only used to store the result and not part of the inputs.

DIVIDE Statement -

What is the use of DIVIDE statement?

DIVIDE statement performs division operations.

What are the different formats of DIVIDE statement?

DIVIDE statement has below different formats based on phrases -

  • Simple DIVIDE statement.
  • DIVIDE with INTO|BY and GIVING.
  • DIVIDE with ON SIZE ERROR (Error Handling).
  • DIVIDE with INTO|BY, GIVING and REMAINDER.

What is the significance of the GIVING in DIVIDE statement?

The value of variable1 is divided by the value of variable2, the result is stored in variable3 coded with the GIVING phrase, and the remainder is stored in variable4 coded with the REMAINDER phrase.

COMPUTE Statement -

What is a Compute Statement?

COMPUTE is used to perform all kind of arithmetic operations in a single expression. The arithmetic operators used in COMPUTE statements are + (ADD), - (SUBTRACT), * (MULTIPLY), / (DIVIDE), and ** (EXPONENT).

What is the use of the COMPUTE statement in COBOL, and how is it different from the MOVE and ADD statements?

COMPUTE statement can use all the arithmetic operators in a single expression.
MOVE statement use to move data from one source to other.
ADD statement to perform addition operation.

Frequently Asked Questions -

What are the precedence rules for arithmetic expressions?
How do you use the GIVING clause in COBOL, and what is its purpose?