C++11 range based loop: How does it really work

Every iteration of the loop creates a local variable x and initializes it to the next element of vec. When the loop iteration ends, x goes out of scope. A single x is never modified.

See this link for the precise semantics.

Leave a Comment