On a test I was asked the question
Give a definition of a variable
A named location in memory.
The teacher marked my answer as wrong and said I need to add that variables can change.
I don’t think the teacher is correct here, as “constants” are an example of a variable that cannot be changed, and the question only asked for a general definition of the term.
What is the real definition?
The C language does not define such a concept as "variable", so in the context of C, the answer is that it's undefined, or defined by whoever is writing about/discussing C and using it to mean something specific to their context.
The closest thing to "variable" in C is an "object", and it is defined in 3.5:
region of data storage in the execution environment, the contents of which can represent values
2 NOTE When referenced, an object may be interpreted as having a particular type; see 220.127.116.11.
In C some objects are
const-qualified, which may disqualify them from being "variables" in the eyes of some/many people using the language. On the other hand,
const-qualified objects do not behave as constants that can be used in constant expressions; rather, they're like all other objects, except that any attempt to modify their values produces undefined behavior.
Note that the word "variable" does appear a number of times in the standard, mostly in the context of "variable arguments" (
stdarg.h) or "variable length arrays"/"variably modified types". However it is also used informally in a number of examples and notes, and some normative text, presumably to refer to objects, but without ever being defined.