Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
93 views
in Technique[技术] by (71.8m points)

c++ - The comparison statement


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

int a=30,b=1, c=5, i=10; i=b<a<c;

i=b<a<c

is interpreted as:

  1. compute (b<a)
  2. compare the result to see if it is < c
  3. place that result into the variable i

So this is what happens:

  1. b<a is evaluated as 1<30, which is true, so the result is 1 .
  2. next this 1 result is compared to c, which is evaluated as 1< 5, which is also true, so that result is also 1
  3. this final 1 result is set as the value in the variable i.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...