Multiple choice

What happens when a string variable is compared to a numeric variable?

  1. The variables are compared character by character until one of the values is different.

  2. The variables are ignored.

  3. An error will occur.

  4. The second variable is automatically changed to the data type of the first variable.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Programming languages enforce type compatibility when comparing variables. You cannot directly compare a string variable (which stores text) to a numeric variable (which stores numbers) because they represent different kinds of data. This type mismatch will generate an error rather than attempting an invalid comparison.