✔ 最佳答案
Can I answer this in English?
2009-03-30 22:30:26 補充:
究竟最上面既#include有咩用?
The lines with "#" in C is for the C preprocessor "cpp". Before the compiler will process the source file, the preprocessor will process the "macros" of the file. All macros are lines begin with "#" character.
Good example is to use the math functions. Without the #include <math.h> line, you may not be able to get a good a.out file and will not get a clean compile.
To see what the output after preprocessing looks like, you can use
> cpp somefile.c
You can think of using the include lines are just short hands not to type in all those function declarations. However, there are more to just that. #include lines can also be in the middle of a program and there are more than just include. It can be #define , #if ...
有時試過唔洗打呢d都run到個program
其實真實既用途係咩?
Sometimes without using any include lines, the compilation will work. It is because C will assume all functions return int and takes int by default. It is the same reason you can compile and specify no libraries (just cc somefile.c). That will work because by default C will link with libc in /usr/lib or /lib. This (just cc somefile.c) may not work if you use any functions that is not in the standard library. A good example is sin().
究竟入面有邊d function係需要用到先要打上去?
Not necessary. Many programmers (including myself) put in more than enough includes just in case. This will waste compile time but there are not harm done to the output. However, in a large or complex environment, you may have problem with this approach. It is a good habit of using the right amount of includes (or #define ...) in a source file.
Under DOS/Windows environment, things are a bit different (such as location of the files) but the idea is the same.