Both questions are relying on platform and compiler specific items. This is bad, because such things are not truly portable. When you study C++, you should focus on more general things that work on all or almost all systems. Learning something specific and thinking it's always true will bite you later on when you least expect it.
Let's take their first question. How is 2321 represented in memory? The answer might surprise you: We don't know. Each system is free to keep memory organized in any way they want. Motorola-based systems usually keep integers in big-endian format, while Intel-based chips generally keep integers in little-endian format. This can be quite confusing, and you should write programs that do not assume anything about the underlying implementation, with an obvious exception being that you are writing software specific to that system.
Now here's two ways 2321 might be represented in memory, assuming an integer is 32-bits:
Big Endian:
Code:
00000000 00000000 00001001 00010001
Little Endian:
Code:
00010001 00001001 00000000 00000000
Little Endian "reverses" the bytes around from what you might naturally expect the number to be.
What they mean by saying 9 and 17 is that one byte in the answer taken by itself makes up the number 9 and the non-zero byte by itself makes up the number 17. Your book might be assuming natural arrangement, such as how the number would be represented in registers and such (and I suppose that might not really truly be endian-independent), but to ask specifically about memory deserves such a long answer.
Now taking your second question.... Unless they clarified the question to a purely mathematical sense, the question is again an answer of "we simply don't know". The problem lies in the ++ and -- operators. In C and C++, we can't guarentee the order in which they will be executed inside of a function. One might be operated before the other.
Take this example:
Code:
int x = 5;
int z = ++x + --x
It might resolve to any of these:
Why? Because compilers are free to set the order of those operations. Your book is again appearing to assume way too much with regard to how a system will implement such expressions.
I took from your example and wrote this bit of code:
Code:
#include <iostream>
int main()
{
int a = 9;
int b = 1;
int c = 2;
int Result = c-- + (b++ - --b) * a + c;
std::cout << "Result = " << Result << std::endl;
return 0;
}
My output:
So, as you can see, you can't rely on how such an expression will be resolved since we all disagree on what the answer is.
I suggest you consider getting a different book to learn from.