Home computickets What is the literal?

What is the literal? [Duplicate]




In the following example, 1 and cat is a literal, and a1 , c and cat – the variables:

int a1 = 1;
int c = a1;
string cat = "cat";

If the “literal” is a fixed value, then why is it when there is a terminology, the term “constant”?

Answer 1, Authority 100%

Because the programming constant – it variable with landline value


At the same time, and most value a variable – it is, in general, also constant


It seems, therefore, to avoid ambiguity of interpretation – what are we still talking when programming utter the term constant – coined the term literal


Therefore, programming is usually understood as:

  • constant – it variable , containing fixed value (nonsense, if you think about – “variable” and at the same time “fixed” but it so happened)
  • literal – is the very fixed value , which is assigned to variable-constant , or even somehow used in the program (in general, it is not necessarily somewhere to assign)

Answer 2

constant and literal – are separate entities

constant – is the data that you can not change

and literals – a certain numeric or numeric prefixes and suffixes that describe the data that is stored in variables and constants

const float pi = 3.1415; // pi - constant
const float pi = 3.1415f // f - literal showing that the number of float type has 3.1415

or for example in C++ for 11 literals were time –

auto delta = 250ms;

ms – a literal

i.e. when you use the const – are you talking about the compiler that the value of this variable can not be changed directly (there are detours, but now is not about that)

And when you use literals, you tell the compiler how to interpret the data that you record in the variable

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions