Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed What is function #include

+30 votes
asked Sep 5, 2021 by pratish vanakhade (230 points)
closed Nov 4, 2022 by Admin
closed with the note: answered

10 Answers

+2 votes
answered Sep 5, 2021 by saranya d (180 points)

#include is a preprocessor in c program that includes the content of the other file to the source code where #include is declared 

+8 votes
answered Sep 5, 2021 by Peter Minarik (84,720 points)
edited Sep 15, 2021 by Peter Minarik

#include copies the content of an entire file to the location of the #include call.

In practice, it is most commonly used to include header files, that is to reference function prototypes, data types, constants, etc that are stored in a single file.

E.g.

#include <string.h>

will reference all the C library functions and constants that are related to C-string manipulations.

0 votes
answered Sep 13, 2021 by Legen-T-ask (140 points)

#include is an Header file which is inbuild command user cant change

its used to include the functions and many more like math.h & conio.h & stdio.h

#include <string.h>

+1 vote
answered Sep 14, 2021 by Vinod Ahirwar (160 points)
C Language: #include Directive

This C tutorial explains how to use the #include preprocessor directive in the C language.

Description

In the C Programming Language, the #include directive tells the preprocessor to insert the contents of another file into the source code at the point where the #include directive is found. Include directives are typically used to include the C header files for C functions that are held outsite of the current source file.

Syntax

The syntax for the #include directive in the C language is:

#include <header_file>

OR

#include "header_file"

header_file

The name of the header file that you wish to include. A header file is a C file that typically ends in ".h" and contains declarations and macro definitions which can be shared between several source files.

Note

The difference between these two syntaxes is subtle but important. If a header file is included within <>, the preprocessor will search a predetermined directory path to locate the header file. If the header file is enclosed in "", the preprocessor will look for the header file in the same directory as the source file.

Example

Let's look at an example of how to use #include directives in your C program.

In the following example, we are using the #include directive to include the stdio.h header file which is required to use the printf standard C library function in your application.

/* Example using #include directive by TechOnTheNet.com */

#include <stdio.h>

int main()

{

   /*

    * Output "TechOnTheNet began in 2003" using the C standard library printf function

    * defined in the stdio.h header file

    */

    printf("TechOnTheNet began in %d\n", 2003);

    return 0;

}

In this example, the program will output the following:

TechOnTheNet began in 2003

Header Files

This is a list of the header files that you can include in your program if you want to use the functions available in the C standard library:

Header File Type of Functions

<assert.h> Diagnostics Functions

<ctype.h> Character Handling Functions

<locale.h> Localization Functions

<math.h> Mathematics Functions

<setjmp.h> Nonlocal Jump Functions

<signal.h> Signal Handling Functions

<stdarg.h> Variable Argument List Functions

<stdio.h> Input/Output Functions

<stdlib.h> General Utility Functions

<string.h> String Functions

<time.h> Date and Time Functions

You will find these header files very useful as you become more familiar with the C language.
0 votes
answered Sep 14, 2021 by Aditya Tiwari (210 points)

#include directive tells the preprocessor to insert the contents of another file into the source code at the point where the #include directive is found. Include directives are typically used to include the C header files for C functions that are held outsite of the current source file.

0 votes
answered Sep 14, 2021 by Amit Sharma (140 points)
#include function is a headr file which is use in code.

every header file has its specific work.

for ,example #include <string.h>is use for string operations and #include<math.h>is use for arithmetical operations.
0 votes
answered Sep 15, 2021 by Eman Sajid (140 points)
we use this preprocessor directive to add different library function
0 votes
answered May 15, 2022 by Maha (140 points)

The preprocessor directive is used to include the header file from the library. The preprocessor is the command that gives instructions to the C processor. Preprocessor directives start with a hash symbol #and after that include a keyword. 

The #Include preprocessor tells the compiler where to find the different standard identifiers such as printf getc, scanf, etc.

Example:

#include<stdio.h>

0 votes
answered May 26, 2022 by userdotexe (1,340 points)

#include is a directive to the C pre-processor to include the contents of another file into the compilation stream

Courtesy of this quora question.

:)

0 votes
answered Oct 25, 2022 by Harshith .R (360 points)

#include is a way of including a standard or user-defined file in the program and is mostly written at the beginning of any C/C++ program. This directive is read by the preprocessor and orders it to insert the content of a user-defined or system header file into the following program. These files are mainly imported from an outside source into the current program. The process of importing such files that might be system-defined or user-defined is known as File Inclusion. This type of preprocessor directive tells the compiler to include a file in the source code program. Here are the two types of file that can be included using #include:

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...