answersLogoWhite

0

A function requires an include directive whenever it makes use of a data type or function that cannot be forward declared, or where a forward declaration would be undesirable, and where a complete declaration of that type or function exists in another file.

That may sound far more complex than intended, but it's really quite simple. The include directive is a signal to the compiler that the specified file is to be inserted into your file in its entirety, just as if you'd typed all the code it contains by hand. This is clearly a huge time saver when it comes to common data types and functions, but how do you decide if an include directive is actually required or not? Simple: comment out the directive and attempt to compile. If it fails, the directive is required. The errors raised will indicate exactly what types or functions it exposes and where they are used.

Most C/C++ programmers split their declarations from their definitions. Declarations of functions and data types (including class declarations) are usually placed in a header file (.h), while the definitions of the functions are safely tucked away in a separate source file (.cpp). Programmers are rarely interested in the implementations -- the header should contain all the information necessary to make use of the functions and data types contained therein. But in order to compile, the source file must include the header file. And if the two files must include other files, then we generally place those directives in the header file thus ensuring that the header contains all the necessary information to allow it to be included in other files.

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

What are its program components?

the main() function,the#include Directive, the variable definition. function prototype, program statements, the function definition,program comments and braces are the components of program in C++


What is function of include in c language?

The #include directive is used to tell the preprocessor that the specified file's contents are to be included at the point where the directive appears, just as if you'd typed those contents in full yourself. Include files are primarily used to organise declarations of external variables and functions, complex data types, constants and macro definitions. The code need only be declared once, and included wherever required. Think of include files as a means of providing forward declarations without having to retype those declarations in full. The definitions of those declarations needn't be contained in the included file, but they must be made available to the program, either as a linked library or as a separate source code file which includes those same declarations. The include keyword is used in C to tell the linker what libraries your code is going to be using.


What are the three required sets of statements for every function that a programmer writes in C plus plus?

There is no requirement for any statement in a C++ function, let alone three sets of statements. For instance, the following is a perfectly valid function: void foo(){} Clearly this does nothing as it has no statements in the function body, but it is nevertheless a valid function. Perhaps you mean something else by "statements". The only requirement of a function is that it have a return type, a valid name, an argument list and a function body. The return type may be void, of course, and the argument list may be empty, but it must include the ellipses. The function declaration need not include the function body, and the argument list need only specify the type of argument (the argument names are optional and need not match those declared in the actual definition). The function name and the arguments define the function signature (the prototype), thus the three required "components" of a function are the return type, the signature and the function body.


What type of language is directive?

Assembler.


Which directive informs the compiler in which any custom server control added to the page or not?

Register directive informs the compiler in which any custom server control added to the page or not

Related Questions

What are its program components?

the main() function,the#include Directive, the variable definition. function prototype, program statements, the function definition,program comments and braces are the components of program in C++


What is a pre-processor directive?

#include is a preprocessor directive. So is #define, #if, etc


What statement do you need to include in a value-returning function?

In a value-returning function, you need to include a "return" statement to specify the value that the function should return back to the caller.


In your program what if you do not provide the following directive in your code using namespacestd hint what will you need to do?

If you do not include the directive using namespace stdin your program, any references to objects in namespace std will need be be qualified with that namespace. For instance...cout


What is function of include in c language?

The #include directive is used to tell the preprocessor that the specified file's contents are to be included at the point where the directive appears, just as if you'd typed those contents in full yourself. Include files are primarily used to organise declarations of external variables and functions, complex data types, constants and macro definitions. The code need only be declared once, and included wherever required. Think of include files as a means of providing forward declarations without having to retype those declarations in full. The definitions of those declarations needn't be contained in the included file, but they must be made available to the program, either as a linked library or as a separate source code file which includes those same declarations. The include keyword is used in C to tell the linker what libraries your code is going to be using.


How do you create a user defined header file?

Header files are not much different from usual cpp files. There are basically two different things. It's file extension: you need to choose "header file" when you create it or save as .h file. Second is header files do not have main() function. When you are done with you header file do not forger to include it in your project by writing preprocessor directive:#include "your_header_file.h"


How do you include a file in PHP?

To include a file in PHP all you need to do is use the include() function as I have shown you in the example below. <?php include("filename.php"); ?>


What is directive and non-directive approach to rural development?

comprehensively describe the directive and non-directive approach to rural development


What are some things that need electricity to function properly?

Some things that need electricity to function properly include smartphones, computers, refrigerators, air conditioners, televisions, and lights.


What is the directive of an essay question?

The directive of an essay question is the specific task or instruction that tells you what you need to do in your response. It guides you on the focus, approach, or perspective you should take when writing your essay.


What is need of header file?

The compiler can only see one translation unit at a time, so every translation unit that calls a function (but does not define it) must at least declare that function. Headers allows us to share declarations consistently amongst many translation units with a simple #include directive. Headers can also declare data types, aliases, constants and macros. Functions can also be defined in headers, but these must be declared inline.


What is the difference between a DoD manual and a DoD directive?

Directives establish or describe policy, programs, and organizations. They also define missions, provide authority, and assign responsibilities. Instructions include more detail on how to implement a directive.