Function Basics | C Programming Tutorial

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

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

  • @dorsia6938
    @dorsia6938 2 года назад +41

    Great video, I love the fact you take the time to explain the core functionality behind things, metioning relationships and comparisons between other things we've already learned, instead of just glossing over code.

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

      Thank you very much for the positive feedback, I'm really glad to hear that you enjoyed the "style" of the video. :-)

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

      True.... His way of teaching is superb..... I feel like a great programmer every time I watch this videos.... Thank you @portfolio courses...

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

      @@robertmaina337 You're welcome Robert! 😀

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

      Ķm

  • @jacobpark9334
    @jacobpark9334 9 месяцев назад +4

    A dude that knows how to explain at the perfect pace and thoroughly, thanks!

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

      You’re welcome, I’m glad you enjoyed the explanation! :-)

  • @mikemuso9542
    @mikemuso9542 2 месяца назад

    Man im not kidding this channel is the only one that i can understand C lang. You're amazing, keep it up dude!!!

  • @kylemlsantos97
    @kylemlsantos97 Год назад +6

    Thank you for helping visual learners! Your content is valued and appreciated

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

      You're very welcome, I'm glad you're enjoying the content! :-)

  • @efekucukyeter9574
    @efekucukyeter9574 2 года назад +2

    The compiler joke got me. Thank you for the explanation.

  • @902Steeler
    @902Steeler Год назад +4

    You cleared up alot of unknowns for me here. Thank you

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

      I'm glad it cleared things up for you Phil, and you're welcome! :-)

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

    Thank you very much. It's one thing to read and understand a book, but it's also very easy to lose your way when implementing those concepts from a book. This put me back on track, and now I understand why I am making mistakes with my functions.

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

      You're very welcome Lenora, I'm glad this video was able to help you out! :-)

  • @omniyambot9876
    @omniyambot9876 8 месяцев назад

    the super inefficient multiplication is funny but definitely learned😂

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

    Thank you! Very well explained.

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

    Nice video! also very helpful that you share the code you used in the video :)

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

    Can we actually call out mult() function inefficient, if eventually the compiler produces assembly code that multiplies by addition for all high-level multiplications?

  • @animeworldamv5052
    @animeworldamv5052 8 месяцев назад

    Your so great at explaining thank u so much, new subscriber

    • @PortfolioCourses
      @PortfolioCourses  8 месяцев назад +1

      You’re welcome, I’m glad you enjoyed it, and welcome aboard! :-)

  • @jeremytay7658
    @jeremytay7658 2 года назад +2

    Hi, thanks for the video, may I know why is there a "0" in "return 0" and "int result = 0"? What does the 0 mean? Is there any other video I can see to find out why?

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

      Great question Jeremy! :-) This video explains the main function return values: ruclips.net/video/CBfhcRQVpf8/видео.html. In the "mult" function in this video, we start result off at zero with int result = 0, but then use the add function to continually add y to the result, before finally returning the result.

  • @kingisfar
    @kingisfar 4 месяца назад

    thank you for the amazing explanation

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

    Hi could you make a tutorial video how you installed gcc on mac and how you use it on terminal i am really having problem with it please.

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

    What if the parameter has 2 different data type? can float and integer be in a same parameter? example- convert(int a, float b);

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

    why do we need to return value sir?

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

    7:00 important point that your college professors won't explain every .

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

    Hello, you mentioned the variable result cannot the be used outside of the add function. It appears again in mult however. Is the program/compiler going to know both result variables are different even though they appear in two functions? Thank you

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

      Great question! :-) So even though they have the same name, those are two different variables called result, each belonging to a different function (the “scope” of the variables). This video covers variable scope in more detail: ruclips.net/video/IVJoByfBcZs/видео.html

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

    I was a bit lost in the function calling other functions example...
    I couldn't get how you did the multiplication... 😔

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

      These can be pretty tricky concepts unfortunately! But basically if we have something like 4 x 7 = 28, we can think of it as 7 + 7 + 7 +7 = 28. In other words, adding four 7 values together.
      So we have an add() function that will return the result of adding a and b, so if we pass it add(0,7) it will return 7. If we pass it add(7,7) it will return 14. If we pass it add(14,7) it will return 21. And if we pass it add(21,7) it will return 28.
      Our mult() function performs the multiplication by repeatedly calling add 'x' number of times using the loop, just like that example above, with add(result,y), where y is the right operand of our multiplication x * y with mult(x,y). And the function starts off result at 0, and calls add with add(result,y) each time, but it stores the value returned by the call to add back into result. So if the first time result is 0 then we'll call add(0,7) and it's going to return 7 (which gets stored into result). And the NEXT time we call add we'll have add(7,7) which is going to return 14 (which again gets stored into result). And then we call add(14,7) and get 21, and then again with add(21,7) to get 28. And at that point we'll have done the x=4 adds, and the loop will stop, and the function returns the result.
      Hopefully this helps somewhat! :-)

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

      This was helpful sir.. I really appreciate.. for the fact that you respond to every message that comes in the comment section is something to appreciate.. thank you sir

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

      @@Codewitheyezyc You're welcome! 🙂

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

    Why do we need function declaration if we can just express the whole function before the main function? I don´t understand

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

      Great question Marek! :-) You could technically put the whole function definition before main and it will work. You could do this if you had multiple functions as well. But then if you have many functions defined, you would need to either scroll through or read through them before finding the main function. If we use function prototypes, when reading our file from top to bottom, at the top of are file we are made aware of the functions that will be defined, and then we would next see the main function. From a readability perspective, this is generally going to be much easier for a programmer to read and understand. :-)

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

      @@PortfolioCourses thanks a lot, much clearer now

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

      @@mareknovak1147 You're welcome! 😀

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

    Great video!

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

    that fun fact i discoverd is when i use for() with its brackets " {} " u must replace that return out of the loop ---> for(){} return result;

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

    Thanks for the video

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

    I don't understand why u used a for loop with 'i' when u did not declare 'i' as a variable.. or is it another way of declaring a variable 'i'?????

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

      Great question! 🙂 So we declare i in the for loop itself with:
      for (int i = 0; i < x; i++)
      result = add(result, y);
      Specifically where it says "int i = 0;". This is another way of declaring a variable. The variable i will have the "scope" of the for loop, which means the variable will "exist" inside the for loop only.

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

      @@PortfolioCourses that question of the boi jumped into my mind and i was like no way its gonna work until i saw that i = 0 xdd , was a relly fun short story . u earned my sub

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

      @@rekt5262 Welcome aboard! 🙂

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

    even if u dont write return result; the output is showing me as 9..didnt get wht return is used fr ?

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

      I would have to see your code to know what's going on there. :-) Maybe you can paste it in as a comment? In order to return a value from a function the regular way, we do need to use a return statement of some kind.

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

      @@PortfolioCourses man if u gt a chance not to use a return keyword,thn hw would u write the code in generic terms

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

      @@PortfolioCourses k

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

      @@PortfolioCourses check the code=i removed return keyword bt the result is still getting printed
      #include
      int main() {
      int fun1(int s1,int s2){
      int s3=s1+s2;

      }
      int output=fun1(5,12);
      printf("the result is: %d
      ", output);
      }

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

    Good video!

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

    this is so helpful

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

    helpful video thank u so much

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

      You're welcome Razan, I'm glad you found the video helpful! :-)

  • @alinadiaz-by1zn
    @alinadiaz-by1zn 10 месяцев назад

    I love you

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

    i really like your explaintion, i'm not good in english but i wanna say thank you sir 🤍

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

      I’m glad you enjoyed the explanation, and you’re very welcome! :-)