Sign in to follow this  
Nanook

first chapter

Recommended Posts

Nanook    537
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

Share this post


Link to post
Share on other sites
Nanook    537
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?

Share this post


Link to post
Share on other sites
SiCrane    11839
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this