G
G
golil2016-11-23 11:26:32
Programming
golil, 2016-11-23 11:26:32

What is the difference between an operand and a literal?

Are operands and literals the same thing? Or is there a difference? Can you please explain in simple terms?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
jcmvbkbc, 2016-11-23
@jcmvbkbc

The word "literal" is translated as "literal". It is an object whose value is its literal value. For example: "hello" is a string literal with the value "hello". Or 42 is an integer literal with the value 42. The opposite of a literal, in a sense, is a variable. A variable is an object whose value is the last value assigned to it. For example: char a[] = "hello world"; a is a string variable, with the value "hello world". Or int answer = 40 + 2; answer is an integer variable with value 42.
The operand is the argument to the operation. In many contexts, literals and variables can be operands. For example: a[0]; the operation here is [], taking an element of the array, the operands are a and 0, one of them is a variable,

A
Anatoly Scherbakov, 2016-11-23
@Altaisoft

# "Hello world" - литерал
print("Hello world")

# somevariable - не литерал
print(somevariable)

# сложение - бинарная операция
# x и 3 - операнды
# а 3, кроме того, и литерал
x + 3

E
Eugene, 2016-11-23
@zolt85

What Wikipedia says:
A literal is an entry in the source code of a computer program that is a fixed value. A literal is also a representation of a value of some data type.
Operand (English operand) in programming languages ​​is an argument of an operation; data that is processed by the team; a grammatical construction denoting an expression that specifies the value of an operation argument. Sometimes an operand is a place, a position in the text where the argument of the operation should be.
We conclude that an operand and a literal are not the same thing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question