# Does it make sense to discuss this ?

This is a problem seen in Zhihu , A lot of comments . Some of them mentioned , What's the use of studying this thing ? We can't write that when we program . I remember when I was in College , Our vice president teaches us lessons , Just mention it to us , Get used to and like using
「( 」 and 「)」, These two symbols .

So the expression above , If you want to express your intention , It can be written like this
((x += 5) == 4)
Or maybe
(x += (5 == 4))
But why do some programmers like to write like this ?

We can be sure , People who write code like this , You must be familiar with operator priority . If as a programmer , He thinks he needs to know operators like a finger , He thinks people can understand the code at a glance , It's no problem that he wrote such code .

What's the use of learning such code ?

Learning this doesn't mean we have to write this code , But , If we are working and studying , Encountered code like this , We can see the function of this code at a glance .

C There are hundreds of pages of language standards , Most people don't study every detail carefully , Some engineers think something is useless , Probably because he didn't use it in his job . Some programmers like to study or need to use this method in their work , That's one of the reasons this code exists .

# Expression and operator precedence

C Language in an expression , If several operators are encountered , Priority and combination direction should be considered .

such as , expression x pri1 y pri2 z, There are two possibilities

(x pri1 y )pri2 z

x pri1 (y pri2 z)

If operator pri1 Priority ratio of pri2 high , So that's the first case .

If operator pri1 Priority ratio of pri2 low , So that's the second case above .

If the priority is the same , Then we should consider the combination direction .

The combination direction is 「 Left to right 」 perhaps 「 Right to left 」.

for example ,「= 」 The combination direction of 「 Right to left 」.


a = b = c   The meaning of an expression is a =( b = c  )

and 「+」 The combination direction of 「 Left to right 」


a + b + c   The meaning of an expression is (a + b) + c

#C Language operator priority

# Parse the above expression
x += 5 == 4
「+=」 The priority of 14

「 ==」 The priority of 7

So the meaning of the above expression is
x += (5 == 4)
Run it

# The ingenious use of expression

Many people don't use this ingenious way of writing , I have seen one in the code these two days , Screenshot for you to see , It's simple , It's also a clever way , It's interesting . Normally , We will still x = y
Written in if outside , Write directly in if It's still interesting .

What will be output if it is written as follows ? Comments give your answers ~
#include "stdio.h" int main(void) {  int x = 2;   int y = 4;  int z = 4;  
 if( x = y >= z){   printf("-----------01\n");  }  return (0); } 

  reply 「  Big belly of basketball 」 Enter technology group chat

reply 「1024」 obtain 1000G Learning materials

©2019-2020 Toolsou All rights reserved,
Python+OpenCV Detailed explanation of face recognition technology SpringBoot practice ( five ):mybatis-plus In BaseMapper,Iservice and ServiceImpl Google says home office affects work efficiency !2021 Return to offline office in 2010 C Language programming to find a student's grade vue Of v-if And v-show The difference between C Language console games , Make bricks These songs , Programmers, don't listen ! What should I do if I suddenly encounter a question I can't answer during the interview ?python To solve the problem of dictionary writing list in c Linguistic 5 Three common sorting methods