Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the definition of a "variable"?

The standard states that

An entity is a value, object, reference, function, enumerator, type, class member, template, template specialization, namespace, parameter pack, or this.

This implies that a "variable" is not an entity.

But further in the standard said:

Every name that denotes an entity is introduced by a declaration. Every name that denotes a label is introduced either by a goto statement (6.6.4) or a labeled-statement (6.1).

and

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable’s name denotes the reference or object.

I'm assume from this two quotes that a variable is a name.

It is because the variable is introduced by declaration of reference and every name that denotes entity introduced by a declaration. But what does a variable's name mean? A variable is also a name by definition.

like image 702
St.Antario Avatar asked Oct 01 '22 16:10

St.Antario


2 Answers

I'm assume from this two quotes that a variable is a name.

No, from the quotes you provided, a variable is an object or a reference which has a name.

It is because the variable is introduced by declaration of reference and every name that denotes entity introduced by a declaration.

The declaration introduces both the variable (the object or reference), and its name. This doesn't imply that that variable is the name, just that both are introduced by the declaration.

like image 132
Mike Seymour Avatar answered Oct 23 '22 09:10

Mike Seymour


The definition of the term variable is a bit ambiguous in this respect, but by looking at the various uses of the term variable in the c++ standard, it looks like a variable is a special kind of entity. It is either an object or a reference. However, not all objects or references are variables, only the ones introduced the way described in [basic]/6:

A variable is introduced by the declaration of a reference other than a non-static data member or of an object. The variable's name, if any, denotes the reference or object.

Note that some variables are unnamed, for example the parameter of the function f in the example below:

void f(int) {}

int main() {}
like image 32
Supremum Avatar answered Oct 23 '22 08:10

Supremum