No video

Static Local Variables | C Programming Tutorial

  Рет қаралды 8,665

Portfolio Courses

Portfolio Courses

2 жыл бұрын

Examples of using static local variables in C. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

Пікірлер: 24
@flirtyemy042
@flirtyemy042 2 жыл бұрын
Straight to the point and easy to understand videos. Earned a sub
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Thank you Chukwuemeka! :-D
@sphanie
@sphanie 2 жыл бұрын
really helpful, simple explanation!!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I'm glad it was helpful for you! 😀
@stevehageman6785
@stevehageman6785 Жыл бұрын
Nice tutorials.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thank you Steve! :-)
@walterzaq1
@walterzaq1 4 ай бұрын
Thanks!
@justcurious1940
@justcurious1940 Жыл бұрын
Great video Kevin, Thanks .
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome! :-)
@Anonymous-XY
@Anonymous-XY 8 ай бұрын
Thank you Kevin.
@fifaham
@fifaham Жыл бұрын
Very helpfull presentation, also a time stamp maybe added as per time frame in @5:12
@PortfolioCourses
@PortfolioCourses Жыл бұрын
I'm glad you enjoyed it! :-) And agreed a timestamp would be a good idea when logging.
@user-xy1ji1dl6y
@user-xy1ji1dl6y Жыл бұрын
شرح عظيم
@PortfolioCourses
@PortfolioCourses Жыл бұрын
:-) على الرحب والسعة
@bsykesbeats
@bsykesbeats Жыл бұрын
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
@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. 🙂
@bsykesbeats
@bsykesbeats Жыл бұрын
@@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
@PortfolioCourses Жыл бұрын
@@bsykesbeats 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.
@qneqne8440
@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
@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
@qneqne8440 Жыл бұрын
@@PortfolioCourses It does help. Thank you very much for such a thorough explaination
@PortfolioCourses
@PortfolioCourses Жыл бұрын
@@qneqne8440 You're welcome! 🙂
@user-el3sj3kh2b
@user-el3sj3kh2b 3 ай бұрын
Thanks!
@PortfolioCourses
@PortfolioCourses 3 ай бұрын
Oh wow thank you so much for the super thanks!!! :-D
strcpy() and strncpy() functions | C Programming Tutorial
8:15
Portfolio Courses
Рет қаралды 37 М.
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 59 М.
How I Did The SELF BENDING Spoon 😱🥄 #shorts
00:19
Wian
Рет қаралды 35 МЛН
Lehanga 🤣 #comedy #funny
00:31
Micky Makeover
Рет қаралды 27 МЛН
Local, Global , Static Variables (in C) - Types of variables
14:27
Static for Classes and Structs in C++
9:12
The Cherno
Рет қаралды 348 М.
A const int is not a constant.
9:16
Jacob Sorber
Рет қаралды 67 М.
Scope of Variables - Local vs Global
11:12
Neso Academy
Рет қаралды 395 М.
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 351 М.
Function-like Macros | C Programming Tutorial
24:12
Portfolio Courses
Рет қаралды 19 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
struct Basics | C Programming Tutorial
24:44
Portfolio Courses
Рет қаралды 135 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 786 М.