And im confused about the fact that if you write in ide #include some header file which tells computer to find some library,
Be careful with terminology. #include
tells the compiler to find some header. The word library in C usually refers to the file with compiled code (.a
, .lib
, .so
, .dll
).
and your compiler will find that code and combine it with your code.
This is right. By and large, the effect is the same as copying and pasting the contents of the header in the place of the #include
statement.
But then how does compiler find that code? Like i just type in #include Cs50 for example.
The compiler has default search paths built in, where it looks for the header that is being #include
d. Typically directories like /usr/include
and /usr/local/include
are built into the compiler, as well as the current directory .
. You can add more search paths through compiler command line arguments, for example -I/some/path
in gcc and clang.
But how does it find that code when i dont have it on my pc
It doesn't. You will get an error like "Cs50: No such file or directory".
If this works on your university's system, probably the header is installed on that system in some central location.
why would i have it without finding it online and downloading it beforehand? Does it look online and then download file which it uses now and in future for my programs when i call #include?
It doesn't.
And if so does it mean that you cant properly program without connection to internet?
C was developed in the 1970s. The internet barely existed yet. You can program perfectly well in C without an internet connection – if you can do it without StackOverflow, of course ;)