What is a sub-expression in C?

c, expression

Solution

A sub-expression is not just any part of a larger expression.

Consider:

2 * 3 + 4 * 5

Here `3+4*5` is not a sub-expression.

The full expression parses as

(2 * 3) + (4 * 5)

and so the direct sub-expressions are `2*3` and `4*5`.

Each of those again parse as compositions of smaller things, with `2*3` composed of the sub-expressions `2` and `3`, and with `4*5` composed of the sub-expressions `4` and `5`.

These sub-expressions of sub-expressions are indirect sub-expressions of the original full expression, so that in total it has these sub-expressions: `2*3`, `4*5`, `2`, `3`, `4` and `5`.

While e.g. `3+4*5` is not a sub-expression.

In summary, a sub-expression is an argument to an operator or function, and such an argument expression can itself have sub-expressions.

Regarding your example

a*(b+C/d)/20

and your concrete questions

`b+c/d` is subexpression is it correct? or alone `c/d` is subexpression ?

Yes, and yes (modulo uppercase/lowercase typo).

However, for example, here `b+C` is not a sub-expression.

Problem

What is sub expression in C? I thought combination of smaller expression is subexpression eg: `a*(b+C/d)/20` `b+c/d` is subexpression is it correct? or alone `c/d` is subexpression ?

Original source