"THE C Programming Language" Reading Note 2

zhaozj2021-02-16  89

Chapter II: (This article is first filed on the second bookstore "

The content of this chapter is the most basic thing in learning and programming. Any language will tell you that he supports data types, those computments, those features, and those that are not perfect. Learning these things is relatively monotonous, trouble, but only through this labyrinth, you can enter the magical field of C. Therefore, at least half of the success of beginners comes from "patience." Oh, is it ready?

The content of this chapter is still very simple, but the author's words hide a lot of important information, not paying attention, will slip from our eyelids, and will list one by one.

the first. Variables and constants. Many people are very vague of their differences. Individuals think that their main difference is whether or not to allocate memory space, in other words, there is a left value. What is the left value? In the second chapter, you can't find this noun from the beginning, huh, huh, you can find him in the entry of variables in the appendix, in fact, the address of the variable, the variable is defined, the left value is determined, until he The survival end. The value of the variables we usually said is the right value of the variable. This is the object we can operate. According to this theory, then it is not difficult to know that the object being modified by const is not a constant. He has a left value, but there is a small trouble here, in this chapter, the beginning of the constant is constant (this chapter has a second section) () Description), I didn't have this supplement. It seems that it should be an understanding of the translator. One example in "C Expert Program" proves that my thoughts are correct, the example is as follows:

#include "stdio.h"

#include "stdlib.h"

#define one 1

Const Int TWO = 2;

int main ()

{

INT IX = 1;

Switch (ix)

{

Case ONE: Printf ("this is 1"); / * ok * /

Break;

Case Two: Printf ("this is 2"); / * error * /

}

System ("pause");

Return 0;

}

Everyone knows that after Case can only express expression with constant, so the variables modified by const are not constant, but the right value of the variable is generally not changed. You can also feel the difference between #define and const from above.

second. About the change sequence. This more places called escape characters, most of them have some special features characters, in the last note, you have seen his power, let's take another code:

#include "stdio.h"

#include "string.h"

#include "stdlib.h"

int main ()

{

IX;

IX = Strlen ("/ 0Abc");

Printf ("THIS IS% D / N", IX);

IX = Strlen ("/ 007Abc");

Printf ("THIS IS% D / N", IX);

System ("pause");

Return 0;

}

You will find that the length of the two almost strings is completely different, what is going on? The first we can understand that: / 0 is a string end value, so anything thereafter does not count the contents of the string, so the length is 0. But the second? We checked the Change sequence list to know '/ 007' This is a character, so the length is 4. At this time, why didn't you understand '/ 007'? '' '/ 0''0''' 7 '? If this is the length of 0, we don't have any human plug-in symbol, huh, obviously, this and the specific implementation of the compiler, with our existing knowledge, you can't understand this, just leave, wait "aware" One day, believe me, this is definitely a kind of enjoyment. Third, about operators, there is a very classic topic on many textbooks, the code is as follows:

#include "stdio.h"

#include "stdlib.h"

int main ()

{

INT IX, IY;

IY = 1;

IX = (iY ) (iY ) (iY );

Printf ("THIS IS% D / N", IX);

IY = 1;

IX = ( IY) (IY ) (iY );

Printf ("THIS IS% D / N", IX);

IY = 1;

IX = ( IY) ( IY) (iY );

Printf ("THIS IS% D / N", IX);

IY = 1;

IX = ( IY) ( IY) ( IY);

Printf ("THIS IS% D / N", IX);

System ("pause");

Return 0;

}

Oh, is it very dizzy? This is nothing more than the problem of adding, this earth man knows that this is not described here, but such a program itself has a big problem, the compiler is not necessarily from left to right (some) It is calculated by the traversal of the tree), so you will find that different compiler results will be different. There is a very complete explanation of this chapter, I will not say more, in short, this test itself is contrary. The characteristics of the language.

转载请注明原文地址:https://www.9cbs.com/read-11913.html

New Post(0)