Tell me, what is the difference between these two ways to connect the header file in C:

#include <stdlib.h> 

and

 #include "stdlib.h" 

    3 answers 3

    When using angle brackets, the file is searched for in a specific list of directories, which is specified in the -I compiler settings.

    When using quotes, the file is searched first of all in the directory of the program itself, then in a certain list, which is set in the -iquote compiler -iquote .

    Not sure if I understood correctly, but in Russian literature I did not notice the descriptions of these two methods.

    Source: http://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html

    • Thank. I remembered hearing something like that somewhere. - user5639
    • files in quotes are unequivocally searched in directories that are set when the compiler is called with -I . - avp
    • @avp, gcc.gnu.org is not an authoritative source? :) - insolor
    • And here is the source ??? Take the tc program: #include <stdio.h> #include "ah" main () {printf ("% d \ n", NNN); } we make the ah file with \ #define NNN 100 in ../ avp @ avp-xub11: ~ / src / tst $ gcc tc -I .. avp @ avp-xub11: ~ / src / tst $ ./a.out 100 avp @ avp-xub11: ~ / src / tst $ gcc tc tc: 3: 15: fatal error: ah: There is no such file or directory compilation interrupted. avp @ avp-xub11: ~ / src / tst $ Questions? - avp
    • 3
      Guys, I am bastard. Such an elementary subject is sucked on the second day. - skegg pm

    Angle brackets mean that the <stdlib.h> file will be taken from some standard directory, usually / usr / include. Quotes "" "indicates a character string Quotes are not part of a string. They are introduced only to mark its beginning and end. The preprocessor replaces this line with the contents of the stdlib.h file.

    • 2
      The quotation marks "" in the #include directive do not mean a text string, but the fact that the file will be searched first of all in the directory where the given source lies - insolor

    Quotes "" this is for the Preprocessor to search the file in the current directory for this line and therefore cannot be thrown out.

    • one
      Not only in the current, but in all directories specified with the -I flag when compiling. Those. if in the tc file there is a \ #include "ah", then the gcc tc -I / tmp -I .. -I ./xaxa command will look for a file named ah in the directories ./ .. / tmp and ./xaxa - avp