Race condition: Min and Max range of an integer

前端 未结 4 891
南旧
南旧 2020-12-30 20:44

I was recently asked this question in an interview.

Given the following code, what will be the min and max possible value of the static integer num?

4条回答
  •  渐次进展
    2020-12-30 20:49

    Well, My answer would be Max 25, and Min 0, since all of your operations are increment, and you initialized it as 0.. I think the static non-volatile int is thrown in there to make you go into these thoughts about race conditions, but is there anything in there that would DECREMENT the number in any situation?

    Edit: For what it's worth, this would be a typical distraction that they may expect you to be able to overcome in the real world, justifying such "trickery", there are a lot of red herrings!

提交回复
热议问题