Range Based For Loop | C++ Tutorial

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024
  • ХоббиХобби

Комментарии • 17

  • @davidkim617
    @davidkim617 2 года назад +5

    I'm a beginner C++ programmer, and to me your explanation is just perfect. Thanks!

    • @PortfolioCourses
      @PortfolioCourses  2 года назад +1

      You're welcome David, I'm glad to hear it was helpful! 😀

  • @lucasgroves137
    @lucasgroves137 Год назад

    Nice one yet again, Kevin. Appreciate the clarity and of course as always, the utter lack of fluff. 👍

  • @franzageek
    @franzageek 10 месяцев назад +1

    I cannot get the range-based for loop to work with my on-heap array. How come?

    • @PortfolioCourses
      @PortfolioCourses  10 месяцев назад

      This stackoverflow answer coves this issue and has a workaround too: stackoverflow.com/a/15919834. :-)

  • @karimbousmaha4038
    @karimbousmaha4038 Месяц назад

    Plz share a Playlist about making some games with graphics in c++

  • @ValliNayagamChokkalingam
    @ValliNayagamChokkalingam Год назад +1

    Thanks once again for everything! char my_array [] - here my_array is essentially a pointer to the first character - so when we declare a string using a pointer directly - char* my _array = "Portfolio"; - why am I getting this error -
    Error (active) E0144 a value of type "const char *" cannot be used to initialize an entity of type "char *' - I am also not able to modify individual characters in a string after declaring the string because of the read only permission. Thanks!

    • @PortfolioCourses
      @PortfolioCourses  Год назад +1

      This video may answer some of your questions regarding char * vs char [] and storing strings: ruclips.net/video/Qp3WatLL_Hc/видео.html. It looks like you may run into issues trying to use strings stored this way with range-based for loops, the recommendation seems to be to use it to create a proper string in C++: stackoverflow.com/questions/18020517/using-range-based-for-loops-with-char-pointer-string.

  • @rajendranm2204
    @rajendranm2204 Год назад

    hi, is it possible to print a int* which is pointing to 3 elements using Range Based For Loop?

  • @aadhuu
    @aadhuu 2 года назад

    Nice explanation!

  • @aegr4923
    @aegr4923 2 года назад

    how do if i want to print the indexes of the array?, example : cars indexes of 1, ship indexes of 2 etc

    • @PortfolioCourses
      @PortfolioCourses  2 года назад

      Great question! :-) You could use a variable like this answer here on Stackoverflow: stackoverflow.com/a/15149476. Or instead of a range-based for loop you could use a regular for loop instead with a counter variable i that keeps track of the index in the array: ruclips.net/video/8CdKMqW4LC4/видео.html. If you want the array index, then a range based for loop probably isn't the best approach, I would suggest using a regular for loop instead.