C++ pass arrays to functions 💵

Поділитися
Вставка
  • Опубліковано 28 січ 2025

КОМЕНТАРІ • 24

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

    #include

    double getTotal(double prices[], int size);

    int main()
    {
    double prices[] = {49.99, 15.05, 75, 9.99};
    int size = sizeof(prices)/sizeof(prices[0]);
    double total = getTotal(prices, size);

    std::cout

  • @andrewchen861
    @andrewchen861 Рік тому +8

    bro's so good at teaching and makes it fun, thanks so much!

  • @-hackers_industry
    @-hackers_industry Рік тому +8

    Bro makes learning fun, yet is so underrated :(

  • @lastwaveundergroundsaviour7037
    @lastwaveundergroundsaviour7037 2 роки тому +10

    damn, everything was straight forward until this video😅 shit i still dont know how to pass arrays to functions after watching this 5 times

    • @ibrahimouhamou9732
      @ibrahimouhamou9732 2 роки тому +2

      Peace be with you
      dude, just make it five times without looking

    • @disabledfabrication
      @disabledfabrication Рік тому

      I RENAMED some "variables" and "parameter" so that it makes more distinction between MAIN method and GETOTAL method.
      Make sure you didn't missed every Bro Code's lesson.
      ~~~
      #include
      double getTotal(double prices[], int size);
      // (METHOD) MAIN ENTRY-POINT
      int main()
      {
      // MAIN'S VARIABLE (It means that everything inside here is only accesible inside this method)
      double prices[] = { 49.99, 15.05, 75, 9.99 };
      int size = sizeof(prices) / sizeof(prices[0]);
      double total = getTotal(prices, size); // Calls the getTotal() method returns a value (in this context, it is a double data-typed value)
      std::cout

    • @ivanpaulcerillo2452
      @ivanpaulcerillo2452 2 місяці тому +1

      Do you get it now?

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

    Nice Video keep it up.

  • @crooda3681
    @crooda3681 9 місяців тому +1

    Arrays do not know their size, they are just memories full of stuff in it. So when u do array[index], it will try to remember if that index has something in it or not. so it just try to remember it, it does not know the size but the memory made it able to remember the stuff in it. If u want to know the size u need to find it ur own since the arrays are too dumb to count and need some help counting it since they're just memories

    • @rsbah
      @rsbah 6 місяців тому

      Lol thank you for this 😂
      I learned java, and java arrays have the size built in, so this C++ array quirk was confusing to me

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

      Why do we have to give an array an initial size If it doesn’t know the size anyways

  • @TóthMáté-c6n
    @TóthMáté-c6n 3 місяці тому +1

    Couldn't we do this with a for each loop?

  • @anjalihegde1596
    @anjalihegde1596 10 місяців тому

    can't we use foreach loop for this?

    • @user-lyf4isnt7daijobu
      @user-lyf4isnt7daijobu 7 місяців тому

      we can :)

    • @yashraj52_
      @yashraj52_ 4 місяці тому

      @@user-lyf4isnt7daijobu hey tried but it is showing me error "this range-based 'for' statement requires a suitable "begin" function and none was found"

    • @user-lyf4isnt7daijobu
      @user-lyf4isnt7daijobu 4 місяці тому

      @@yashraj52_ oh yeah tried it myself jus now.. my bad :(
      we can do this tho..
      #include
      #include
      double getTotal(const std::vector& prices);
      int main()
      {
      int size;
      std::cout size;
      std::vector prices(size);
      for (int i = 0; i < size; i++)
      {
      std::cout

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

      @@yashraj52_ bro i think it also decays to pointer

  • @yahyaarfaoui8526
    @yahyaarfaoui8526 Рік тому