Function Basics | C Programming Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ส.ค. 2024

ความคิดเห็น • 63

  • @dorsia6938
    @dorsia6938 ปีที่แล้ว +36

    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  ปีที่แล้ว +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 ปีที่แล้ว +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  ปีที่แล้ว

      @@robertmaina337 You're welcome Robert! 😀

    • @ajaykumarmajhi6206
      @ajaykumarmajhi6206 ปีที่แล้ว

      Ķm

  • @jacobpark9334
    @jacobpark9334 4 หลายเดือนก่อน +3

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

    • @PortfolioCourses
      @PortfolioCourses  4 หลายเดือนก่อน

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

  • @kylemlsantos97
    @kylemlsantos97 ปีที่แล้ว +5

    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! :-)

  • @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! :-)

  • @efekucukyeter9574
    @efekucukyeter9574 ปีที่แล้ว

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

  • @omniyambot9876
    @omniyambot9876 4 หลายเดือนก่อน

    the super inefficient multiplication is funny but definitely learned😂

  • @animeworldamv5052
    @animeworldamv5052 4 หลายเดือนก่อน

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

    • @PortfolioCourses
      @PortfolioCourses  3 หลายเดือนก่อน +1

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

  • @EfthimiaAthan
    @EfthimiaAthan ปีที่แล้ว +4

    Thank you! Very well explained.

  • @zodack8477
    @zodack8477 11 หลายเดือนก่อน

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

  • @dasura9147
    @dasura9147 ปีที่แล้ว

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

  • @jeremytay7658
    @jeremytay7658 ปีที่แล้ว +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  ปีที่แล้ว

      Great question Jeremy! :-) This video explains the main function return values: th-cam.com/video/CBfhcRQVpf8/w-d-xo.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.

  • @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.

  • @dimasaditya4034
    @dimasaditya4034 10 หลายเดือนก่อน

    why do we need to return value sir?

  • @saiidramadan4055
    @saiidramadan4055 2 ปีที่แล้ว +2

    Thanks for the video

  • @rekt5262
    @rekt5262 ปีที่แล้ว

    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;

  • @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: th-cam.com/video/IVJoByfBcZs/w-d-xo.html

  • @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);

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      Great question, and yes, that is allowed. :-)

  • @pappisedi
    @pappisedi ปีที่แล้ว

    this is so helpful

  • @TheHset
    @TheHset ปีที่แล้ว

    Great video!

  • @razankanji5088
    @razankanji5088 ปีที่แล้ว

    helpful video thank u so much

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว +1

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

  • @mareknovak1147
    @mareknovak1147 ปีที่แล้ว

    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

      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 ปีที่แล้ว

      @@PortfolioCourses thanks a lot, much clearer now

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      @@mareknovak1147 You're welcome! 😀

  • @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! 🙂

  • @thegospelmessages8730
    @thegospelmessages8730 ปีที่แล้ว

    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  ปีที่แล้ว

      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 ปีที่แล้ว

      @@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  ปีที่แล้ว

      @@rekt5262 Welcome aboard! 🙂

  • @aabirraghib8826
    @aabirraghib8826 ปีที่แล้ว

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

    • @PortfolioCourses
      @PortfolioCourses  ปีที่แล้ว

      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 ปีที่แล้ว

      @@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 ปีที่แล้ว

      @@PortfolioCourses k

    • @aabirraghib8826
      @aabirraghib8826 ปีที่แล้ว

      @@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 ปีที่แล้ว

    Good video!

  • @my_evil_side2977
    @my_evil_side2977 11 หลายเดือนก่อน

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

  • @alinadiaz-by1zn
    @alinadiaz-by1zn 5 หลายเดือนก่อน

    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! :-)