It is funny how I feel like I have taken seemingly simple things like this for granted. Even after using C off and on for many years, I still learn some new subtle things about the language, especially from watching your videos. Thank you for this.
@NOPerative2 жыл бұрын
Awesome job describing header file usage and importance. Additionally, good to see you're back and making more content for 2022 - good stuff.
@leythecg2 жыл бұрын
Very clearly explained! Many, many thanks for that!
@roopibhai1556 Жыл бұрын
thank you man for explaining global and external in simple way with actual demo.
@boryswwa Жыл бұрын
Thanks for this explanation. Simple and straightforward. Exactly what I needed!
@hossamnasser9717 Жыл бұрын
Your simple way of explanation is unique. Your videos make me love coding. Thanks, man
@OmarIghirouaiour-c2p7 ай бұрын
It's just simple and important things that I've learned from this video
@romakekua82492 жыл бұрын
Hello from Georgia
@reshmaimmaculater.48682 жыл бұрын
Thank you so much for this video. I was looking for more clarity on this topic.
@nishant18772 жыл бұрын
Thank you for this video..This video is a necessity for anyone who works in a real team environment and do real coding not interview coding
@neetorstar4502 жыл бұрын
Life saver. I was cracking my brains on that
@shinsban23742 жыл бұрын
thanks you!
@fusca14tube2 жыл бұрын
Hi... Thanks for this video. I've one question: if you are including the "global.h" file in multiple .c files, is there a need to protect the extern declaration? I mean, do you need to use #ifndef in this "global.h" file?
@CodeVault2 жыл бұрын
No. extern int x; is just a declaration of the variable x and you can declare the same variables as many times as you want. It might improve compile time if you use that "#ifndef" or "#pragma once". I'll research some more on this topic and might make a video on it
@fusca14tube2 жыл бұрын
@@CodeVault Thanks for the reply! :)
@chenmoney19202 жыл бұрын
Nice explaination
@vladimir_khlghatyan2 жыл бұрын
What if don't create the file "global.c" and declare global variables directly in the header file "global.h"?
@CodeVault2 жыл бұрын
Basically the definition of all of those symbols might appear multiple times in your project. For variables I'm pretty sure it's fine (but not recommended). The compiler sort of, cleans up the duplicated global variables. But if you do this with the functions you'll have a problem if you include that global.h file in multiple .c files from your project. This video talks about this topic: code-vault.net/lesson/ys1aqurr3x:1642707892012
@KFlorent132 жыл бұрын
You were back and I missed it. I have failed you...
@alvarogaliana3271 Жыл бұрын
Rather than modifying the x, I'm trying to retrieve its value in the main2.c function. But apparently this doesn't do it, when I print x in main2.c is set back to 0. Is there any way to do this? I thought global variables would do the trick. Edit: I must use two distinct executable files for this, that's kind of required for my project.
@CodeVault Жыл бұрын
With two distinct executables you will have to have some mechanism of communication between the two. Global variables are per process (they never get shared between processes). Either use a fifo or a simple file to communicate between processes
@raghavimadhwa23362 жыл бұрын
Hey, I have one doubt. If I want to share a global variable across two C files which are in different directories, then how to do that?
@CodeVault2 жыл бұрын
Same as you would do if they were in the same folder. In the gcc compile line add the full path to them and in the include you can specify a relative path to the current folder.
@saikishorekemburu3454 Жыл бұрын
Hey I have a doubt, If I want to access a global variable and change the value of that variable in another file.how can I?
@CodeVault Жыл бұрын
You can do that just like with any other variable. Simply assign a different value to it in a function in that other file like so: variable = 15;
@tekshanmadhawa4632 Жыл бұрын
Hey, good explanation but I have one doubt ? when you rrun both files in same terminal in VS code which file's integrated terminal was used ? I am confused actually .
@CodeVault Жыл бұрын
There's a big misconception here. I'm not "running files" as in, I am not running a specific source code. The gcc command compiles all the source codes specified (main.c, main2.c, main3.c) into a single executable called "main". I am executing this "main" file that includes the code of all the other .c files
@markm46032 жыл бұрын
Why is c so simple and python I just struggle to understand
@CodeVault2 жыл бұрын
I'm sure you can get to understand Python as well! It just has some nifty tricks that you can do in one line which would be translated to many many lines of code in C. Once you understand those it's not too difficult I think