Difference between #include and #include" " in C/C++ with Examples
Last Updated :
22 Apr, 2023
Pre-requisites: Header files in C/ C++ and its uses
The difference between the two types is in the location where the preprocessor searches for the file to be included in the code.
#include <filename> // Standard library header
#include "filename" // User defined header
#include<filename>
#include<> is for pre-defined header files. If the header file is predefined then simply write the header file name in angular brackets.
Example:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
The preprocessor searches in an implementation-dependent manner, normally in search directories pre-designated by the compiler/IDE. This means the compiler will search in locations where standard library headers are residing. The header files can be found at default locations like /usr/include or /usr/local/include. This method is normally used to include standard library header files.
Example: Below is the C++ program to demonstrate the above concept:
C
// C program to demonstrate
// the above concept
#include <stdio.h>
// Driver code
int main()
{
printf("GeeksforGeeks | ");
printf("A computer science portal for geeks");
return 0;
}
Output:
GeeksforGeeks | A computer science portal for geeks
#include "FILE_NAME"
#include " " is for header files that programmer defines. If a programmer has written his/ her own header file, then write the header file name in quotes.
Example:
#include "mult.h"
Here, mul.h is header file written by programmer.
The preprocessor searches in the same directory as the file containing the directive. The compiler will search for these header files in the current folder or -I defined folders. This method is normally used to include programmer-defined header files.
mul.h Header file:
// mul.h
int mul(int a, int b)
{
return(a * b);
}
Below is the C program to include and use the header file mul.h:
C
// C program to demonstrate
// the above approach
// Include user-defined
// header file
#include "mul.h"
// Driver code
int main()
{
int a = 10;
int b = 20;
// Invoke the function defined in
// header file
int c = mul(a, b);
printf("%d", c);
return 0;
}
Output:
200
#include<> vs #include""
S No. | #include<filename> | #include"filename" |
1 | The preprocessor searches in the search directories pre-designated by the compiler/ IDE. | The preprocessor searches in the same directory as the file containing the directive. |
2 | The header files can be found at default locations like /usr/include or /usr/local/include. | The header files can be found in -I defined folders. |
3 | This method is normally used for standard library header files. | This method is normally used for programmer-defined header files. |
4 | <> It indicates that file is system header file | " " It indicates that file is user-defined header file |
Case 1: Include standard library header using notation #include"".
C
// C program to demonstrate
// the difference
// Header file
#include "stdio.h"
// Driver code
int main()
{
int a = 10;
printf("%d", a);
return 0;
}
Output:
10
Explanation:
#include " " will search ./ first. Then it will search the default include path. One can use the below command to print the include path.
gcc -v -o a filename.c
Case2: Include standard header file using the notation #include<>
C
// C program to demonstrate
// the difference
// Header file
#include <stdio.h>
// Driver code
int main()
{
int a = 10;
printf("%d", a);
return 0;
}
Output:
10
Case 3: Include standard header file using both notation #include"" and #include<>, such as stdio.h
// stdio.h
int add(int a, int b)
{
return(a + b);
}
C
// C program to demonstrate
// the difference between
// "" and <>
// This will include the standard
// header file
#include <stdio.h>
// This will include the user-defined
// header file
#include "stdio.h"
// Driver code
int main()
{
int a = 10;
int b = 20;
// Invoke the function defined in
// header file
int c = add(a, b);
printf("Result of addition is: %d", c);
return 0;
}
Output:

Explanation:
1. When stdio.h is created in the current directory then the code in Case 1 will generate an error but the code in Case 2 will work fine.
2. " " and < > can be included together in the same code and the code will work fine since the search path priority is different for the two notations. Here, "" will include the user-defined header file and <> will include the standard header file.
Similar Reads
Difference between Struct and Enum in C/C++ with Examples
Structure in C++ A structure is a user-defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type. The âstructâ keyword is used to create a structure. Syntax: struct structureName{ member1; member2; member3; . . . member
3 min read
Difference between include() and include_once() in PHP
The include() function in PHP is mostly used to include the code/data of one PHP file to another file. During this process if there are any kind of errors then this require() function will display/give a warning but unlike the require() function in which the execution comes to a halt, the include()
3 min read
Difference between Inline and Macro in C++
1. Inline : An inline function is a normal function that is defined by the inline keyword. An inline function is a short function that is expanded by the compiler. And its arguments are evaluated only once. An inline functions are the short length functions that are automatically made the inline fun
3 min read
What are the differences between C and Embedded C?
C Language C is a general-purpose programming language, which is widely used to design any type of desktop-based applications. It was developed by Dennis Ritchie as a system programming language to develop the operating system. The main features of C language include low-level access to memory, a si
3 min read
Difference between "int main()" and "int main(void)" in C/C++?
Note: This was true for older versions of C but has been changed in C11 (and newer versions). In newer versions, foo() is same as foo(void). Consider the following two definitions of main(). Definition 1: C int main() { /* */ return 0; } C++ int main() { /* */ return 0; } Definition 2: C int main(vo
3 min read
Difference Between C++ Text File and Binary File
A text file is the one in which data is stored in the form of ASCII characters and is normally used for storing a stream of characters. Text files are organized around lines, each of which ends with a newline character ('\n'). The source code files are themselves text files. A binary file is the one
4 min read
Difference Between Structure and Class in C++
In C++, a structure works the same way as a class, except for just two small differences. The most important of them is hiding implementation details. A structure will by default not hide its implementation details from whoever uses it in code, while a class by default hides all its implementation d
3 min read
Difference between virtual function and inline function in C++
Virtual function: Virtual function is a member function which is declared within a base class and is redefined by a derived class. Inline function: Inline function is a normal function which is defined by the keyword inline, it is a short function which is expanded by the compiler and its arguments
2 min read
Difference Between Inline and Normal Function in C++
Inline Function is a function that is expanded inline by the compiler when it is invoked. During function call, a lot of overhead tasks are performed like saving registers, pushing arguments to the stack, and returning to the calling function. These overheads are time-consuming and inefficient for s
4 min read
Difference Between C Language and LISP Language
C Language: C is the procedural Programming language. It was designed to be compiled using a compiler. The Language has small and fixed number of keywords like if/else, for, while,.. etc. We can use more than one assignment that may be used in one statement in this language. Functions are also used
2 min read