first chapter

Started by
3 comments, last by Nanook 17 years, 8 months ago
Hi! I just started on my c++ book (accelerated c++), I've read the first chapter.. but I didnt get what they ment by side effects of an expression.. does anyone mind explaining this for me? Nanook
Advertisement
Did it give an example of code?

Dave
nope.. hmm I can write what it says in the book:

"An expression asks the implementation to compute somthing. The computation yields a result, and may also have side effects--that is, it may affect the state of the program or the implementation in ways that are not directly part of the result. For example, 3+4 is an expression that yields 7 as its result , and has no side effect, and

std:cout << "Hello World!" << std::endl

is an expression that, as its side effect, writes hello, world! on the standard output stream and ends the current line."


Might be me thats tired? I kind of get it, but I dont.. hehe is it possible to explain this easy?
Some expressions are evaluated for their results. Some expressions have side effects. In a = b + c, assuming a, b and c are primitives like ints, then the expression b + c has no side effects; all that happens is the value of b + c is evaluated. However, the expression a = b + c has a side effect, an action that occurs in addition to the value of the expression: it assigns the value of b + c to a.

aha.. I get it.. thanks alot!! :)

This topic is closed to new replies.

Advertisement