C++ Programming
Last Modified: 1/18/2025
Ⅰ C++ Fundamentals
1 C & C++ Introduction
-
C/C++ is a compiled language.
-
C/C++ compilers map C/C++ programs into architecture-specific machine code (string of 0s and 1s).
- Unlike Java, which converts to architecture-independent bytecode (run by JVM => Java Virtual Machine).
- Unlike Python, which directly interprets the code.
- Main difference is when your program is mapped to low-level machine instructions, CPU will directly interprets and runs.
Compilation Advantages
-
Excellent run-time performance:
Generally much faster than Python or Java for comparable code because it optimizes for the given architecture.
-
Fair compilation time:
Enhancements in compilation procedure (Makefiles) allow us to recompile only the modified files.
Compilation Disadvantages
-
Compiled files, including the executable, are arcitecture-specific (CPU type and OS).
Executable must be rebuilt on each new system, i.e., “porting your code” to a new architecture.
-
Instead of “Edit -> Run [repeat]” cycle, “Edit -> Compile -> Run [repeat]” iteration cycle can be slow.
Normal C/C++ Compile & Run:
$ g++ -o hello hello.cpp