what is the distinction between an identifier and variable name in c? That is, what are the limits between both terms? Let's take the following code fragment as an example:
#include <stdio.h>
struct a {
int num;
} a;
void main()
Aside: Don't do that. main() returns an int.
{
a.num = 10;
printf("%d\n",a.num);
}
here a is both a tag and a variable name which are both identifiers and both variables!?!? Unsure of the latter!
thanks
You're right `a' is an identifier in each appearance, but you're
wrong in thinking that both appearances designate variables. To
reduce confusion, let's change your example to
struct tag {
int num;
} var;
All of `tag' and `num' and `var' are identifiers, just like `a' and
`num' and `a' (and `main' and `printf') in your original example.
However, in the revised example only `var' identifies a variable.
`tag' is a part of `struct tag', the name of a type, not the name
of a variable. And `num' identifies one of the elements of a
`struct tag', again not a variable (`var.num' could be called a
variable, but `num' by itself could not be).
An identifier is a bit of source code that identifies something,
it is a name for something. Many identifiers are names of variables,
but programs have other things that can be named. The Standard lists
all the things identifiers can identify (in 6.2.1 paragraph 1):
"An identifier can denote an object; a function; a tag
or a member of a structure, union, or enumeration; a typedef
name; a label name; a macro name; or a macro parameter."
Of these, only "object" is approximately equivalent to "variable;"
the other identified things are all non-variables.
Summary: Identifiers are names; variables ("objects") are one
of the classes of things that have names.