What is Header files (i.e #include<stdio.h>,...) in C/C++ and what is import statement in Java/Python?
Header files in C/C++ are a "copy paste" mechanism. The included header file is literally written into the file while preprocessing (copy pasting the source code together). After that is done, the compiler transaltes the source code. The linker then connects the function calls. That is somewhat outdated and error prone -> can be really frustrating as well when sth doesnt work as expected.
Newer languages have module systems, which are nicer (import simply does it).
In Java and Python we use a similar keyword called import to add a package and use the methods in it. But in advanced languages like Java and Python few packages are imported by default. e.g. in Java java.lang.* is imported by default.
#include directive makes the compiler go to the C/C++ standard library and copy the code from the header files into the program. As a result, the program size increases, thus wasting memory and processor’s time.
import statement makes the JVM/PVM go to the Java/Python standard library, execute the code there , and substitute the result into the program. Here, no code is copied and hence no waste of memory or processor’s time.hence import is an efficient mechanism than #include.
Header files in C/C++ are a "copy paste" mechanism. The included header file is literally written into the file while preprocessing (copy pasting the source code together). After that is done, the compiler transaltes the source code. The linker then connects the function calls. That is somewhat outdated and error prone -> can be really frustrating as well when sth doesnt work as expected.
Newer languages have module systems, which are nicer (import simply does it).
In Java and Python we use a similar keyword called import to add a package and use the methods in it. But in advanced languages like Java and Python few packages are imported by default. e.g. in Java java.lang.* is imported by default.
#include directive makes the compiler go to the C/C++ standard library and copy the code from the header files into the program. As a result, the program size increases, thus wasting memory and processor’s time.
import statement makes the JVM/PVM go to the Java/Python standard library, execute the code there , and substitute the result into the program. Here, no code is copied and hence no waste of memory or processor’s time.hence import is an efficient mechanism than #include.
Other tutorials
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. 作业代写
ReplyDelete