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

Discussion

The declaration
enum cities{ bethlehem, jericho, nazareth = 1, jerusalem }
assigns the value 1 to

  • A.bethlehem
  • B.nazareth
  • C.bethIehem and nazareth
  • D.jericho and nazareth

Answer: D

Correct answer: jericho and nazareth

Enumerators count upward from zero unless given an explicit value, and an explicit value resets the count. So bethlehem is 0, jericho is 1, nazareth is explicitly 1, and jerusalem follows at 2.

Both jericho and nazareth therefore have the value 1. C permits duplicate enumerator values, which is occasionally useful for aliases but is more often an accident - as here, where an explicit assignment collides with the automatic sequence.

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

Post your comment

Please log in or register to post a comment.