Programming Language Textbook D. Part 3

Original author: Ali Çehreli
  • Transfer
  • Tutorial
The third part of the translation of D Programming Language Tutorial from Ali Çehreli . The content of the chapter is designed for beginners and, it seems to me, does not even reveal topics. 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 the assignment operation 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 "make the value of a equal to 10". Likewise, the meaning of the next line is “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 is b”! If you follow the same logic from the previous two lines, then this expression should mean "make the value of a equal to b". Assigning a to b also means "make a the same as b."

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

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 their values ​​are 1 and 2, respectively, after these operations the values ​​will become 2 and 1.

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

Only registered users can participate in the survey. Please come in.

Should I translate chapters with simple material or translate more interesting chapters?


Also popular now: