Machine-translated by Google. Questions are authored in English.
Top

Discussion

For which of the following situation should the register storage class be used?

  • A.For local variable in a function
  • B.For loop counter
  • C.For collecting values returned from a function
  • D.For variables used in a recursive function

Answer: B

Correct answer: For loop counter

register is worth asking for where a variable is accessed very often, and a loop counter is the classic case - it is read and written on every iteration. It cannot be used where the variable’s address is needed, since a register has no address. In practice modern compilers allocate registers better than the hint does, so the keyword is now of historical interest.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.