P
P
Pavel Zaitsev2021-07-31 12:11:53
Programming
Pavel Zaitsev, 2021-07-31 12:11:53

How is a constant different from a variable?

How are variables different from constants?

1. With dynamic typing, you can change the type of a variable, but not a constant.
2. With static typing, you can change the type of a variable, but not a constant.
3. With strong typing, a variable can change its value, but a constant cannot.
4. With weak typing, a variable can change its value, but a constant cannot.
5. With explicit typing, you can change the name of a variable, but not of a constant.
6. With implicit typing, you can change the name of a variable, but not a constant.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vasily Bannikov, 2021-07-31
@OmniaNightmare

Variable is mutable and constant is immutable

1. With dynamic typing, you can change the type of a variable, but not a constant.

Yes
2. With static typing, you can change the type of a variable, but not a constant.

Not
3. With strong typing, a variable can change its value, but a constant cannot.

Yes
With weak typing, a variable can change its value, but a constant cannot.

Yes
5. With explicit typing, you can change the name of a variable, but not of a constant.

Not
6. With implicit typing, you can change the name of a variable, but not a constant.

No
But in general it all depends on the specific YaP.
At least I don't know of any Java in which you can change the name of a variable at runtime

S
shellnet, 2021-07-31
@warlinx

graduate geekbrayz is a constant, and a novice developer is a variable

A
Alexander Skusnov, 2021-08-01
@AlexSku

In fact, the concept of "variable" (identifier) ​​is not so simple.
1) In some Delphi x:= 5; x:= 10 is the address of the memory location where 5 was, then 10.
2) In Python, two objects will already be created (5 and 10), and x is a pointer (first to one, then to the other)
3) In Haskell, x = 5 is not an instruction at all, but a declaration of a function x that will call another function - the data constructor 10.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question