Тёмный

Local vs global variables in C 

Подписаться
Просмотров 18 тыс.
% 431

Source code can be found here:
code-vault.net/lesson/c137erxzxa:1611240649922
===== Support us through our store =====
code-vault.net/shop
===== Check out our website =====
code-vault.net
===== Check out our Discord server =====
discord.code-vault.net

Опубликовано:

 

23 янв 2021

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@tapiocaferoz02
@tapiocaferoz02 3 года назад
It's hard to believe that there is someone who teachs so well a subject that nobody even teach... Thanks for all your videos!
@janaschelle8377
@janaschelle8377 3 года назад
Thank you, sir! There aren't so many channels about C on RU-vid, I am super glad to discover yours! Greetings from Germany!
@brandonmohammed9092
@brandonmohammed9092 3 года назад
Yo hope you're doing good bro. You've helped me with alot and I just noticed you haven't posted in 2 months so hope you're good mentally and you and you're family are safe
@CodeVault
@CodeVault 3 года назад
Thanks man. We're all alright! I'm still active on the Discord server. More videos are coming soon!
@suchithboddu7242
@suchithboddu7242 3 года назад
Really appreciate the way you teach with appropriate examples. I would suggest you to create a playlist for C programming with the proper order of videos.
@CodeVault
@CodeVault 3 года назад
Thanks! All the playlists on the channel are based on topic and as close as possible to a proper order. The videos weren't made with an order in mind so I just ordered them from the easiest to hardest.
@kkrolley
@kkrolley 3 года назад
Sir, keep on doing those! Great vid!
@taylorvaughan3257
@taylorvaughan3257 Год назад
As someone new to C, this is such a fantastic video, and helped me understand something I'd been missing this whole time. People like you who take the time to help others with niche problems, are truly the heroes of the internet! Keep being great!
@eliadamsalem5486
@eliadamsalem5486 3 года назад
good job! waiting for sockets tutorial!!
@sa-ri5kl
@sa-ri5kl 3 года назад
Hi, thank you for these amazing tutorials Please make a video about socket programming.
@parrotparrot1948
@parrotparrot1948 2 года назад
You earned yourself a subscriber :)
@ellipszia
@ellipszia Год назад
an in depth great explanation! Thank you!
@hugo-garcia
@hugo-garcia 3 года назад
I would like a video about how embed assembler instructions within C code
@CodeVault
@CodeVault 3 года назад
Interesting topic, I noted it down!
@brijmohansiyag9668
@brijmohansiyag9668 3 года назад
The additional informations you give are very very helpful and motivates to learn more Thank you bro Love from India❤️
@matteopisati9966
@matteopisati9966 2 года назад
very very well Done ! Thank you
@dylanwalter-gb7kq
@dylanwalter-gb7kq 6 месяцев назад
as a aspiring programmer, this video is one of the best i've seen
@BelallGamall
@BelallGamall Год назад
Really Great ❤
@jellyfish1772
@jellyfish1772 3 года назад
Thank you so much
@brightlyricsmusic
@brightlyricsmusic 3 года назад
Sir please start a java tutorial tooo your teaching is the best.......
@CodeVault
@CodeVault 3 года назад
I will keep that in mind. I might upload some videos on Java
@testvb6417
@testvb6417 3 года назад
i dont know man, you are the best
@talroz8431
@talroz8431 3 года назад
thanks!!! best tutorial!!
@pawanthanay
@pawanthanay 3 года назад
please make a video on generic functions like qsort() and bsearch() Thanks in advance
@ZennyTheMama
@ZennyTheMama 2 года назад
WHAT A CHAD!
@craigkinney853
@craigkinney853 3 года назад
Hi I've been reading forums like stack overflow and geekforgeeks, cprogramming etc. They all mention compilers and the different types of them. People will say 'oh better to use gcc gmw for that' but what really are the differences. If you have the time would you include a layman's explication. Reading the forums can be difficult for beginners. Finally could you point me to one of your videos that explains size_t? I think I saw it somewhere in your videos with a good explication but can't find it again. Thanks in advance.
@CodeVault
@CodeVault 3 года назад
I'll look into the different compilers, I think it's a great topic for a video! You can always search it on our website: code-vault.net Here's the video: code-vault.net/lesson/wkec83yooo:1603733527208
@brightlyricsmusic
@brightlyricsmusic 3 года назад
Sir if it is possible can you provide practice questions on pthreads and Unix processes? Bcoz I am not able to find questions
@mastenaliouat7431
@mastenaliouat7431 3 года назад
keep going you are the best from kabylie
@brightlyricsmusic
@brightlyricsmusic 3 года назад
Sir please upload video about sleep() in pthreads where to place it I am having doubts in that actually in my college I am having os going on and I completed pthreads,process from your channel it would be really helpful for me if you upload video about sleep(), wait() in pthreads and process plzzz
@CodeVault
@CodeVault 3 года назад
It's not that tricky. sleep you call when you want your thread/process to stop its execution for some time. And wait() you call when you want to stop a processes execution until another child process finishes its execution. So they are very different functions
@lenausa6462
@lenausa6462 3 года назад
I dont know man,yor are the best
@wassimboussebha2561
@wassimboussebha2561 3 года назад
Hi can you do a playlist about trees and implementation using C
@CodeVault
@CodeVault 3 года назад
It's on my todo list. I will get to it whenever I have time
@krish5226
@krish5226 2 года назад
Why you're not making videos🥺🥺
@CodeVault
@CodeVault 2 года назад
I will get back to it soon! Be on the lookout!
@ibukiyoshida4125
@ibukiyoshida4125 3 года назад
Will you do a calloc tutorial?
@CodeVault
@CodeVault 3 года назад
I briefly talk about calloc in this video: code-vault.net/lesson/akvjz24gn5:1603733521718
@pranithrshetty437
@pranithrshetty437 3 года назад
Can you make a video on dining philosophers problem?
@CodeVault
@CodeVault 3 года назад
I noted it down
@Кукусик-е2э
@Кукусик-е2э Год назад
🔥Global variables eat more memory, but make code processing easier. 🍀Local variables save memory, but make more memory garbage and decrease processing efficiency.
@CodeVault
@CodeVault Год назад
It's not quite like that. Your first point is mostly correct but they both use the same amount of memory (if they are the same type of course), it's just that local variables can be deallocated in the middle of running the process, thus freeing up some memory for the process to use. Local variables sometimes can decrease efficiency, although it is such a small decrease it's not worth thinking about. It usually just involves increasing or decreasing the stack pointer value which is super quick, only the compiler might do a bit more work to figure out how much memory it needs to allocate for the stack of a specific function call (but this doesn't affect runtime performance).
@Кукусик-е2э
@Кукусик-е2э Год назад
@@CodeVault thanks for your answer! This memory/efficiency thing became very interesting to me since I started coding games which includes Game Loop usage. So, if there is a piece of code in the loop with some method that has a local variable initialization line, plus some extra methods that assign same values to that variable (like getting length or dimention etc.)... well, what happens is that loops iterate hundreds of thousand or even more times per second, all those local variable keep on getting created and destructed hundred of thousand times per second... But if I just get one global variable outside the loop and assign it value just once. Well, I guess I need to write some code to test it all 😄
@CodeVault
@CodeVault Год назад
The local variable's memory is allocated and deallocated only once (even if it is a loop). Of course, the assignment will be done multiple times if it's in a loop. I have to check if for objects in C++ the same applies for constructing and destructing the data. I assume those get called each iteration of the loop
@doragonmeido
@doragonmeido 3 года назад
i was going to comment last seen 8 months ago but then i saw you replayed to a month old comment . i found hope
@CodeVault
@CodeVault 3 года назад
Yes, I am still replying to comments
@doragonmeido
@doragonmeido 3 года назад
@@CodeVault thank you
@parsishashank
@parsishashank 3 года назад
Yes, c programming will follow static scoping.
@GoblinGreen911
@GoblinGreen911 2 года назад
unrelated:i don't understand what the termios.h library does,make a video please explain.
@CodeVault
@CodeVault 2 года назад
I'll look into it!
@189Blake
@189Blake 3 года назад
Sorry for the dumb question, but what are those arguments inside your main function?
@CodeVault
@CodeVault 3 года назад
In this video I explain them: code-vault.net/lesson/dbijqbwu2a:1603733526118
@ProMineWolderfull
@ProMineWolderfull 3 года назад
Hey my friend, do you have any videos about how to get rid of from fgets? I have been trying by using Mystring(strlen(Mystring)-1)= '\0', but when i get to the end of the file this method breaks the last character of the string For example: The last line that the fgets reads is the string MANAGER, then when i use the method above, it outputs MANAGE, Could you help me please? Thank you man, your videos are helping me a lot. :D :D
@CodeVault
@CodeVault 3 года назад
Hmm, to solve this issue you have 2 options: 1) Check if eof was reached in the file (feof(inputFile)) and don't remove the last character in that case 2) The easiest solution would be to just add a after the last line inside the input file. That's what I usually do to make all the lines be exactly the same.
@lucasferrini7063
@lucasferrini7063 3 года назад
Well, kinda late, but you could check if the current char is and the next one is \0 using a for. If that condition checks, replace the current char with \0
@monusolanki5263
@monusolanki5263 3 года назад
How to create c language graphics program in visual studio code
@CodeVault
@CodeVault 3 года назад
It's quite complex. You could either use the native APIs for GUIs (like Win32) or a library with cross platform compatibility like GTK+
@monusolanki5263
@monusolanki5263 3 года назад
@@CodeVault thanks so much sir lots of love ❤️ from India. Also I have one question ..can we add audio file in c program..& how
@monusolanki5263
@monusolanki5263 3 года назад
@@CodeVault plz upload one graphics program video..I have installed GUI library files but I don't know how to linked library files with visual studio code
@CodeVault
@CodeVault 3 года назад
I'll look into it
@mrafayshams3089
@mrafayshams3089 Год назад
I have heard multiple times that global variables are bad practice. I’m more of a embedded C programmer. Why is it the case? Or are global variables, especially those within a same file are okay?
@CodeVault
@CodeVault Год назад
In most Object Oriented languages, you can argue that global variables are bad practice but, in C, it's sometimes a necessity. The main problem with global variables is they can be modified from wherever in your code and it could cause unexpected issues. A lot of the time is better to return a new value (struct or primitive) from a function you're calling so that, instead of working with a global variable, you use the returned value instead (and that value can't changed outside of the scope of that function, unless you explicitly let it to)
@CoderDBF
@CoderDBF Год назад
I gave a dislike because you don't address globals when working with multiple files.
@CodeVault
@CodeVault Год назад
There's a video for that: code-vault.net/lesson/fjri9hcdte:1642359047479