Multiple choice

What is the difference between declaration and definition of a variable?

  1. Both can occur multiple times, but a declaration must occur first.

  2. There is no difference between them.

  3. A definition occurs once, but a declaration may occur many times.

  4. A declaration occurs once, but a definition may occur many times.

  5. Both can occur multiple times, but a definition must occur first.

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

A definition allocates memory for a variable and can occur only once in a program (following the one definition rule). A declaration tells the compiler about the variable's type and name without allocating memory, and can appear multiple times. For example, extern int x; is a declaration, while int x = 5; is a definition.