Questions a

topic

Why C language to be divided. H and. C files, so what are the benefits?

  1. You can declare a function and a variable in the source file?
  2. Can-defined functions and variables in header files?
  3. The same can not declare a function or variable in both the first document?
  4. Can you define the same function or variable in the two source files?

view

* .H header files C / C ++ in the interior contains some macro definitions, declare variables and function definitions

* .C file to generate an executable program file C / C ++ in the interior also contains some declaration macros, functions, and variables are defined

But write separately, conducive to the maintenance and development of the code. Defined in the * .c files, #include statement will be used to open the * .h library, all source code is not in conflict with

As a result, more modular program. When modifying or updating the code requirements, only need to modify its definition in the * .h can modify all the * .c files; otherwise, you need to modify one by one for each * .c file, is not conducive to efficiently develop , has increased the error rate

Now answer these four questions:

First, declare and define functions and variables, and certainly not only in the source file, and can be placed in the header file.

Secondly, for the three, after experiments show that the same can declare a variable or function in the two header files, but can not open two header files at the same time

However, if the use of such methods:

#ifndef XXXXXX
#define XXXXXX
//定义的内容
#endif

It can open at the same time, but only to first open the application library content

For question four, the experiment proved, the same project, two source files may not be defined for a function or variable. But it does not affect the different projects.

Guess you like

Origin www.cnblogs.com/JustinRochester/p/12232558.html