The compiler translates high-level language programs to binary code
Compiled Languages
Compiled language programs are compiled to binary machine code, which is then directly executed by the HW
e.g. C/C++, Rust, Pascal, …
Pros - fast
Cons - need to re-compile on a different HW
Interpreted Languages
Programs are first compiled to an Intermediate Representation, IR, which is then converted by a Virtual Machine, VM to machine code and executed by the HW
e.g. Java, Python, …
Pros - better portability
Cons - slow
Basics of Computer Programming
Computer Program (External View)
Basic elements of a computer program
Input
Process
Output
Computer Program (Internal View)
A list of instructions ordered logically
Usually, involve data access
Developing a C++ Program
Coding
Write source code into a file
e.g. hello.cpp
Compile
Source code is converted to object code in machine language
e.g. hello.obj
Link
Combines objects and libraries to create a binary executable
e.g. hello.exe
Function
A sequence of instructions grouped together, which implement a specific task.
main()
main() is a special function, which is the starting point of a C++ program.
Statement
A syntactic unit that expresses some action to be carried out.
cout
An output function provided by iostream library
cout
Console Output allows our program to output values to the standard output stream
<<
output operator, which output values to an output device
The right-hand side of the << is the string to output
endl
end of the line. advance the cursor on the screen to the beginning of the next line
#include
Include the libraries you want to use
e.g. iostream commonly used functions for I/O, including cout
e.g. cmath commonly used math functions, such as sin()cos()log()
using namespace
namespace
A declarative region that provides a scope to the identifiers inside it
Declare namespace to avoid writing the full name
e.g. std namespace is used such that we can write cout instead of std::cout