Jack
Jack

Reputation: 16724

How is this kind of operation "a = x" or "a++" etc called?

How do people that write compilers call it? I know that int a, b, c; is called an expression. But things like this: int a = 2? or a++, a=c etc I don't have any idea. And where do I find these terms? C standard or buy a book about compiler construction? I hope this is clear. Thanks in advance.

Upvotes: 0

Views: 99

Answers (1)

kennytm
kennytm

Reputation: 523614

int a, b, c;

This is not an expression. This is a declaration.

int a = 2;

This is also a declaration. The 2 part is the initializer.

a ++

This is a "post-increment" expression. Note that outside of the C world this could be just a statement.

a = c

This is an assignment expression (which again, outside of C, this can be a statement).


The exact definition of these terms and categorization of each syntax for C can be found in the C standard (Chapter 6: Language), which you can find download/purchase information from Where do I find the current C or C++ standard documents?.

Note that these are only true for C (and most of its derivatives, e.g. C++, Javascript, etc.). These concepts may not be meaningful in other languages (e.g. some language doesn't distinguish between statements and expressions).

Upvotes: 7

Related Questions