⬆️ ⬇️

Textbook on programming language D. Part 3

The third part of the translation is D Programming Language Tutorial by Ali Çehreli . The content of the chapter is designed for beginners and, I think, does not even reveal the topic. But this is a translation of one of the chapters.



Previous parts:

  1. Part 1
  2. Part 2




Assignment and order of operations



The first two difficulties that most students encounter when studying programming are assignment operations and the order of operations.



Assignment operation



You will see lines similar to the following in almost every program, in almost every programming language.

a = 10; 


The meaning of this line is the following: “make the value of a equal to 10”. Similarly, the meaning of the following line is the following: “make the value of b equal to 20”.
 b = 20; 


Guided by this information, what would be said about the next line?
 a = b; 


Unfortunately, this line is not about mathematical equality, which, I think, we all know. This above expression does not imply “a equals b”! If you follow the same logic from the previous two lines, this expression should mean "make the value of a equal to b". Assigning the value to a to b also means "make the value of a the same as the value of b."

')

The well-known mathematical symbol "=" has a completely different meaning in programming: make the value of the left part the same as the value of the right part.



The order of operations



These program operations are performed step by step in a special order. We can see these previous 3 expressions in the program in the following order:



 a = 10; b = 20; a = b; 


The meaning of these three lines together is: “make the value of a equal to 10, then make the value of b equal to 20, then make the value of a the same as the value of b”. Accordingly, after these three operations, a and b will be equal to 20.



Exercise



Ensure that the following three operations change the values ​​of a and b. If at the beginning of their values ​​1 and 2, respectively, after these operations, the values ​​will be 2 and 1.



 c = a; a = b; b = c; 

Source: https://habr.com/ru/post/243595/



All Articles