Multiple choice

In C, what is the difference between a declaration and definition of a variable?

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

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

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

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

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

A definition allocates storage for a variable and can only appear once in a program. A declaration (like 'extern int x;') only informs the compiler about the type and can appear multiple times across different files or scopes. This is why header files can contain declarations without causing multiple definition errors.