Code example:

int x = 10; int *p = &x; // reference - получение адреса объекта x int y = *p; // dereference - получение объекта по указателю p 

Many books in Russian use the term "dereference" when translating dereference. As I understand the meaning of the word "dereference" - is the deprivation of the name. But there seems to be no name being taken away.

Another version of the translation that I have met is the “removal of indirectness”. This option is closer in meaning to the original.

So why "dereference"?

  • IMHO, you have everything explicitly described in the comments. And everything else (in any case, about C) - verbiage. - PinkTux
  • @PinkTux Well i. translation dereference - incorrect in terms of the meaning of the word in the Russian language? - random
  • one
    Why? Dereferencing - Turning a name into something else seems logical. - MSDN.WhiteKnight

1 answer 1

In fact, the translation is absolutely correct. See what happens:

Any object in any programming language consists of two inseparable entities:

  1. Values ​​(whatever we mean by that)
  2. The name of this value

In many C-type programming languages, the distinction between these entities is not emphasized. For example, in many languages ​​you can write something like:

 a := a + 7; 

Here the same lexeme "a" is used in different senses. Right - as a value, on the left - as a name. Novice programmers often do not realize this. In some languages ​​this distinction is made explicit. For example, in the Shell language, the variable name can be "A", and the value - "$ {A}".

Returning to your question. In many programming languages, there is a special type of variable whose values ​​are the names of other variables. What is a link (pointer)? This machine address is the name of the cell containing the value.

Therefore, “dereferencing” means to tell the processor that the value of this variable should be turned into the name of some other variable. Like this:

 int a; int *pa = &a; a = 3; *pa = a + 4; 

The result is pretty obvious. Actually, we told the processor that:

  • Although pa stands to the left of the assignment character, we are not interested in her name.
  • We need the name of some other variable given by its value.
  • In fact, in this example, the name pa disappears! She is "dereferenced."
  • Thank. Explanations are clear. An example with a meaning and a name is very good: dereference - turning a name into a value. Although it still turns out that the word dereference does not reflect the entire depth of the process that occurs behind it. - random
  • @random, yes there is no "depth" there, this is syntactic sugar, no more :) If you understand what a pointer is, then this is enough. - PinkTux