Incrementals WITH other math functions?

If the value of a is 5, what are the values of b and c?

c = 10*(++a);

b = 10*(a++);



That’s the question I need help with. Specifically, everywhere I look online shows to to deal with something like

a=5

b=(++a)

or whatever, but I can’t find anything that has other operations in it. Do I ignore the 10* part, or what do I do with it? Like, for example, would c=60? Or would it just be 6?

(It’s for a class assignment but I couldn’t afford the textbook and Google isn’t helping.)

Thank you for any help!
The way you've asked your question is somewhat ambiguous, so let me clarify it a bit first. Given:
1
2
3
4
a = 5;
c = 10*(++a);
a = 5;
b = 10*(a++);
The value of c is 60. The value of b is 50.
or whatever, but I can’t find anything that has other operations in it.


(++a) is an expression that increments a, and evaluates to the value of a after it was incremented.

(a++) is an expression that increments a, and evaluates to the value of a before it was incremented.

Therefore:

10*(++a) is an expression that evaluates to the value of (++a) multiplied by 10.

10*(a++) is an expression that evaluates to the value of (a++) multiplied by 10.

Do I ignore the 10* part, or what do I do with it? Like, for example, would c=60? Or would it just be 6?

How would it make sense to ignore things that are part of the code you've written? What kind of language would see that you've written 10*, and just ignore it?
Last edited on
helios and MikeyBoy have answered your question, but just to pick apart what you said one more time:

b=(++a)
or whatever, but I can’t find anything that has other operations in it.
Do I ignore the 10* part, or what do I do with it?

Instead of c = 10 * (++a), break it apart into two lines.
1
2
int temp = ++a;
int c = 10 * temp;

This should be easier to digest.
Last edited on
And for the other:
1
2
3
4
int b = 10 * (a++);
//
int b = 10 * a;
++a;
I literally copied and pasted the part before the blank lines directly from the assignment.
@Mikeyboy I don't know. My teacher doesn't speak much English, I don't have the text book, I've never taken programming, and Google wasn't providing any other examples with a increment and other math functions, at least not that I could find. So based on other, non-programming Google-based school learning I've had, if you can't find any examples, it's possible that it either doesn't matter or the teacher is including it to throw us off.
The trick in (web)search is to use correct keywords. Obviously, if you don't know the topic, guessing effective words is hard.

From "C++ expression" search:
https://stackoverflow.com/questions/7479946/whats-an-expression-and-expression-statement-in-c


The c = 10 * (++a) is an expression. Expression produces/returns a value.
This expression has subexpressions. It is effectively:
c = expr1, where
expr1 == expr2 * expr3
and
expr2 == 10
expr3 == ++a

The expression ++a returns a value, but it has also a side-effect: the value of a is incremented by 1.
Topic archived. No new replies allowed.