0

I am asking since I couldnt immediately find an answer on google, I know the answer is simple.

what does for (char c : str) {} do in a for loop?

Thank you!

4
  • Have a read: en.cppreference.com/w/cpp/language/range-for Commented Feb 3, 2020 at 18:45
  • This is called a range for loop. Commented Feb 3, 2020 at 18:45
  • That is C++ not C which is a different language. Commented Feb 3, 2020 at 18:46
  • Sounds like you could use a good C++ book. It it they will go over the modern changes to C++. Commented Feb 3, 2020 at 18:46

1 Answer 1

3

It iterates the individual characters of str, copying each one to the (local) variable c for use in each iteration of the loop.

Sign up to request clarification or add additional context in comments.

1 Comment

Based on assumptions, that's indeed what happens. Which doesn't mean that a whole boat load of other things could happen.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.