The answer is: "Depends on your compiler and optimization options"
I do not remember if standard tells how compiler should handle these issues, so I suppose it can be anything from nothing (3+4 will be replaced by compile-time constant) or putting 3 and 4 into CPU registers, adding these values, putting them into RAM and finally using them somewhere or deallocating said RAM.
Most up-to-date compilers will just optimize out this line.
if you make this line something like int foo = 3 + 4; most compilers will optimize it and it will behave like int foo(7);
And if you don't use foo variable after, it could be completely optimized out.
EDIT: sample code
1 2 3 4 5 6 7 8 9
#include <iostream>
int main()
{
int x = 3;
int y = 4;
int z = x + y;
std::cout << z;
}
when compiled w/ -O3 (actually even -O1 — but not -O — will suffice) left out all variables, transforming code to the equivalent of std::cout << 7;
Ok, it will add 3 and 4 together and return 7 as result.
No, it doesn't write anything at all.
The first answer is half-correct. The expression 3 + 4 will evaluate to 7, assuming it's executed as written and not optimised away. It doesn't return anything, as such, because it's not a function or a method, but I assume that's what vlad meant.
But that expression doesn't actually do anything. It certainly doesn't write anything. So the second answer is also correct.
Well, I simplified it. 3 + 4 is an expression which evaluates to 7. You can actually see the result using std::cout << 3 + 4;
If you take a look at the answers it tells you:
This statement is an expression that yields the result 7 and has no side effects.
Why would you expect it to output anything at all if you did not even write "std::cout" anywhere? In the future remember: the program does exactly what you tell it to, nothing less and nothing more. If it is not doing something it is 100% of the time because you did not tell it to in that case.
In this case, you told it to add, but you never told it to display the result of adding, so it did not display anything.
Well yeah, but in your response, you said "you did not even write...", "you never told it to...", etc, as if it was his code. I thought you may have missed the context of the OP's question.