Good use of your C (1)

zhaozj2021-02-16  64

The last article felt a good time after writing, so I decided to write some C's articles. The C language is probably a language that is the longest life of life from birth. He brought the highest peak with its simple grammar and higher execution efficiency, but after the object-oriented language appeared, the status of the C language was shaken, but his execution speed was still unmanned. In this case, there is a development of C . He is completely compatible with C and the object-oriented function is strong, but this does not mean that the historical mission of the C language is completed. Some programs still have to write with C, the most typical is Windows API. In fact, there are still some object-oriented prototypes in C, which will be mentioned in subsequent articles that will discuss the use of expressions in this article. Like "Data Type Conversion in Java", the topic of this article seems simple, but it will make you have a lot of gains after reading. As long as it is a slightly programmed person, I know what the expression is a play, so I don't say much. Here I want to say is a very clever usage of some expressions. First, let's take a look at the logical operator && and |. These two operators have a very useful operation, that is, can be used to replace the IF statement. "What? What is the relationship with that?" You may have such questions, let us see a program: #include void main () {int a = 5, b = 45; a B-50 && A ; Printf ("A =% D", a);} The result of this code is: A = 5 From here, you can see that A is not executed. This type of operation is called "short circuit" because A B-50 is equal to 0, so that A B-50 && A is definitely false, and C language In order to improve the performance efficiency, it is not an operational && back. This is the same as if (A B-50) A ; || The principle and && are the same, it is equivalent to IF (! (A B-50)) A ; this will not say much. & And | These although they are bit operators, they can also use a logical operator to use, come and see an example: #include void main () {int a = 1, b = 0; IF (A & B) Printf ("expression is true"); Else Printf ("Expression is false");} The result is: Expression is false This shows that the value of A & B is the same, the same, A | b is equivalent to A || b. After a while, I will explain why their effect is the same. Let's discuss the notorious goto statement.

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

New Post(0)