doubt regarding range based loop in c++

Правка en1, от abhinav700, 2022-08-06 04:50:25

Earlier, i was solving a problem. When i went to discuss section to see the solutions, there was a person who was following a syntax of for loop which i was not able to understand.

it was as follows: for (char &c : word) where word is of type std::string. can someone explain me how is it different from for (char c : word)? because i was getting run time error when i tried to remove & from c.

i tried running it my console, but still was not able to understand it's working properly.

Теги c++, loop, help

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский abhinav700 2022-08-06 04:50:25 570 Initial revision (published)