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.
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.
Can we actually call out mult() function inefficient, if eventually the compiler produces assembly code that multiplies by addition for all high-level multiplications?
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?
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.
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
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
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. :-)
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! :-)
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
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.
@@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
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.
@@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); }
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.
Thank you very much for the positive feedback, I'm really glad to hear that you enjoyed the "style" of the video. :-)
True.... His way of teaching is superb..... I feel like a great programmer every time I watch this videos.... Thank you @portfolio courses...
@@robertmaina337 You're welcome Robert! 😀
Ķm
A dude that knows how to explain at the perfect pace and thoroughly, thanks!
You’re welcome, I’m glad you enjoyed the explanation! :-)
Thank you for helping visual learners! Your content is valued and appreciated
You're very welcome, I'm glad you're enjoying the content! :-)
You cleared up alot of unknowns for me here. Thank you
I'm glad it cleared things up for you Phil, and you're welcome! :-)
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.
You're very welcome Lenora, I'm glad this video was able to help you out! :-)
The compiler joke got me. Thank you for the explanation.
You're welcome! 🙂
the super inefficient multiplication is funny but definitely learned😂
Your so great at explaining thank u so much, new subscriber
You’re welcome, I’m glad you enjoyed it, and welcome aboard! :-)
Thank you! Very well explained.
You’re welcome Efthimia! :-)
Can we actually call out mult() function inefficient, if eventually the compiler produces assembly code that multiplies by addition for all high-level multiplications?
Nice video! also very helpful that you share the code you used in the video :)
You're welcome! :-)
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?
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.
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.
why do we need to return value sir?
Thanks for the video
You're welcome! :-D
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;
Good you learned something new! :-)
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
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
What if the parameter has 2 different data type? can float and integer be in a same parameter? example- convert(int a, float b);
Great question, and yes, that is allowed. :-)
this is so helpful
Great video!
Thank you, I'm glad you enjoyed it! :-)
helpful video thank u so much
You're welcome Razan, I'm glad you found the video helpful! :-)
Why do we need function declaration if we can just express the whole function before the main function? I don´t understand
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. :-)
@@PortfolioCourses thanks a lot, much clearer now
@@mareknovak1147 You're welcome! 😀
I was a bit lost in the function calling other functions example...
I couldn't get how you did the multiplication... 😔
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! :-)
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
@@Codewitheyezyc You're welcome! 🙂
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'?????
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.
@@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
@@rekt5262 Welcome aboard! 🙂
even if u dont write return result; the output is showing me as 9..didnt get wht return is used fr ?
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.
@@PortfolioCourses man if u gt a chance not to use a return keyword,thn hw would u write the code in generic terms
@@PortfolioCourses k
@@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);
}
Good video!
Thank you! :-)
7:00 important point that your college professors won't explain every .
I love you
i really like your explaintion, i'm not good in english but i wanna say thank you sir 🤍
I’m glad you enjoyed the explanation, and you’re very welcome! :-)