Examples of using static local variables in C. Source code: github.com/portfoliocourses/c.... Check out www.portfoliocourses.com to build a portfolio that will impress employers!
Пікірлер: 24
@flirtyemy042 Жыл бұрын
Straight to the point and easy to understand videos. Earned a sub
@PortfolioCourses Жыл бұрын
Thank you Chukwuemeka! :-D
@sphanie2 жыл бұрын
really helpful, simple explanation!!
@PortfolioCourses2 жыл бұрын
I'm glad it was helpful for you! 😀
@justcurious1940 Жыл бұрын
Great video Kevin, Thanks .
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@Anonymous-XY7 ай бұрын
Thank you Kevin.
@stevehageman6785 Жыл бұрын
Nice tutorials.
@PortfolioCourses Жыл бұрын
Thank you Steve! :-)
@walterzaq14 ай бұрын
Thanks!
@qneqne8440 Жыл бұрын
Why not declare calls as a global variable before int main (void) and calls++ later on in the code. Would that cause problems?
@PortfolioCourses Жыл бұрын
We try to avoid global variables when possible because global variables can lead to more difficult to trace bugs. When a function is limited to only working with its own variables, and we have a bug that involves one of those variables, we know to look in that function for the bug. But if many functions work with a variable, and there is a bug involving that variable, then we need to look at many functions to find the bug (which takes more time, and is more confusing to figure out... which function caused the problem, when was it called, etc.). By making the variable a local static variable, only the one function can access it, which is better for debugging purposes than using a global. Hopefully this helps! :-)
@qneqne8440 Жыл бұрын
@@PortfolioCourses It does help. Thank you very much for such a thorough explaination
@PortfolioCourses Жыл бұрын
@@qneqne8440 You're welcome! 🙂
@bsykesbeats4013 Жыл бұрын
Is there any way to retrieve the current value of the static variable? In Effective C by Robert Seacord, one of the exercises is to "Add a retrieve function to the counting example form Listing 2-6 to retrieve the current value of the counter". Listing 2-6 is just an increment function with a static variable btw: void increment(void) { static unsigned int counter = 0; counter++; printf("%d ", counter); } How could I add a function to retrieve the value if the scope is limited to the increment function? Wouldn't returning an int from increment() be the only way? (But if you did that, you wouldn't be able to retrieve the current value without incrementing it).
@PortfolioCourses Жыл бұрын
If the increment function were to return a pointer to the static int, then I suspect the other function could use the pointer to retrieve the value by dereferencing it. Though I've never tried that before. It's the only thing I can think of though. 🙂
@bsykesbeats4013 Жыл бұрын
@@PortfolioCourses Gotcha. Any benefit of returning a pointer instead of an int? ... only other option I guess is to rewrite increment() to write to a log like you did and then write retrieve() to read from the log I guess...I appreciate the response.
@PortfolioCourses Жыл бұрын
@@bsykesbeats4013 Not in particular that I can think of. 🙂 Maybe if other functions also wanted to modify that variable's value, then a pointer would be useful.
@fifaham Жыл бұрын
Very helpfull presentation, also a time stamp maybe added as per time frame in @5:12
@PortfolioCourses Жыл бұрын
I'm glad you enjoyed it! :-) And agreed a timestamp would be a good idea when logging.
@user-xy1ji1dl6y Жыл бұрын
شرح عظيم
@PortfolioCourses Жыл бұрын
:-) على الرحب والسعة
@user-el3sj3kh2b3 ай бұрын
Thanks!
@PortfolioCourses3 ай бұрын
Oh wow thank you so much for the super thanks!!! :-D