C++ recursion explained easy 😵

Поділитися
Вставка
  • Опубліковано 15 гру 2024

КОМЕНТАРІ • 10

  • @BroCodez
    @BroCodez  2 роки тому +13

    #include
    int factorial(int num);
    int main () {
    std::cout 1){
    return num * factorial(num - 1);
    }
    else{
    return 1;
    }
    }

  • @Dazza_Doo
    @Dazza_Doo 2 роки тому

    To avoid Stack Over flow, could you do this: Half way into Recursion, you then exit the function by passing on the information into a new Function (that does the exact same thing) - I would assume that the STACK would clear itself of the first Recursion and be on it's merry way, then you hand the "Batton" (relay running race) back to the Original function and start the cycle all over again?

    • @tabibhassan3376
      @tabibhassan3376 Місяць тому

      well you're in a for loop. so the steps will decrease every time. Basically you're iterating but not manually rather calling the main function. (sorry for late answer)

  • @FrederikWollert
    @FrederikWollert 7 місяців тому

    Awesome Video. Is it not necessary to have a faster and memory efficient Program in sorting and Searching Algorithm programs?

  • @Tevadaa
    @Tevadaa 3 місяці тому

    Thank you bro code ur the goat fr

  • @wlsedlacek
    @wlsedlacek Рік тому +1

    how is the (steps - 1) stopping the result from going into loop? isnt (steps -1) just =99 ?

    • @masterali2837
      @masterali2837 Рік тому +3

      well yes then 99 becomes 98 then 97 and soo on until 0 then it does not run the if statement anymore and breaks out of the functions (this is pretty simple to understand im just guessing your first programing experience is with c++ but i recemend python for starting)

  • @baddarelsherif7234
    @baddarelsherif7234 Місяць тому

    Love u❤😊