Difference B/W range for Loop & foreach In C++?

Поделиться
HTML-код
  • Опубликовано: 8 мар 2017
  • JOIN ME
    -----
    RUclips 🎬 / @cppnuts
    Patreon 🚀 / cppnuts
    COMPLETE PLAYLIST
    ------------
    C++ Tutorial For Beginners: • Introduction To C++
    STL (Standard Template Library): • STL In C++
    ThreadIng In C++: • Multithreading In C++
    Data Structures: • Data Structure
    Algorithms: • Binary Search
    Design Patterns: • Factory Design Pattern...
    Smart Pointers: • Smart Pointer In C++
    C++14: • Digit Separator In C++
    C++17: • std string_view in C++...
    C++ All Type Casts: • static_cast In C++
    INTERVIEW PLAYLIST
    ------------
    C++ Interview Q&A: • Structural Padding & P...
    C++ Interview Q&A For Experienced: • How delete[] Knows How...
    Linked List Interview Questions: • Find Kth Node From Bac...
    BST Interview Questions: • Search Element In Bina...
    Array Interview Questions: • Reverse An Array
    String Interview Questions: • Check String Is Palind...
    Bit Manipulation Questions: • Find Set Bit In Intege...
    Binary Tree Interview Question: • Invert Binary Tree
    Sorting Algorithms: • Bubble Sort
    C++ MCQ: • Video
    C MCQ: • What printf returns af...
    C Interview Questions: • Designated Initializat...
    QUICK SHORT VIDEOS
    -------------
    C++ Short : • C++ Short Videos
    C Short : • Shorts C Programming MCQ
    In this video we see what is the difference between range based for loop and foreach loop in c++ programming language. For more details please watch full video and do let me know if there is any doubts in comment section.
    #cpp #interviewquestions #programming #tutorial #coaching #beginners #computerscience #softwareengineering

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

  • @gaurishgangwar
    @gaurishgangwar 3 года назад +9

    This is wrong. You can use traditional arrays in for_each.
    Run this code, it will work:
    #include
    #include
    int main()
    {
    int arr[10];
    for(int i=0; i

    • @CppNuts
      @CppNuts  3 года назад +2

      Thanks for correctly pointing it, I have to either shoot a new video or replace it.
      Thanks man.

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

      This comment should be highlighted.

    • @CppNuts
      @CppNuts  2 года назад +4

      Done, thanks..

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

    Which is better to use(specially for
    c++ containers like vector)?

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

    You can use iterators on C-style standard arrays also. The following works.
    #include
    #include
    int main()
    {
    int arr[10];
    for(int i=0; i

  • @druidclash9161
    @druidclash9161 5 лет назад +2

    Please make a video about the difference in the depth of this two iterating approaches

  • @Imahustla90
    @Imahustla90 5 лет назад +1

    You can get iterators for arrays with std::begin() and std::end() functions.

    • @uniksk123
      @uniksk123 3 года назад

      But he says its not possible in traditional arrays not in std : : array !!.

  • @heathledger7291
    @heathledger7291 4 года назад +1

    good video,very helpful

    • @CppNuts
      @CppNuts  4 года назад

      Glad it was helpful!

  • @mentalthink1
    @mentalthink1 5 лет назад +1

    Thanks I don't know about the second For sentence (int i:ar), it's similar to Python when we use for n in something.... Thanks anothert very interesting video...

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

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

    Hi, very informative tutorial. Please pause your video @5:54 for reference. I have a few questions. Can you kindly explain why have you used at Line 9: void print(int val) {cout

    • @tanveerasif5978
      @tanveerasif5978 6 месяцев назад

      if you want to print the value in ar, you should do something like cout