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.)
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 aafter it was incremented.
(a++) is an expression that increments a, and evaluates to the value of abefore 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?
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 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.