近期重新拾起C++,参考了MIT 6.096简洁的课程复习一下,所有笔记整理参考自课程Lecture Notes以及C++文档和相关书籍
L.01 Introduction
1. Line by line explanation
/* Comment here */
# Precocessor ---> dump in the contents of another file
int main(){...} // excute when the program startup
- Namespace: Access an indentifier defined in a namespace
:: // scope resolution operator
using name space std;
- Escape sequences:
\n Newline sequence
\t Tab
\\ Backslash
\' Single quote character
\" Double quote character
return 0
Program tells the OS it has been completed successfully
2. Basic Language Features
2.1 Statement & Expression (Has a value)
2.2 Operators
- Mathematical
- Logical: and, or, etc.
- Bitwise: manipulate the binary representations of numbers (not focused on)
2.3 Data Types
BoolIntegerDoubleDoubly precise floating point numberCharacterchat *A text stringStringA sequence of characters: "Hello World!\n"
3. Variables
- Defination: Give value a name to refer it later. A varibale is a nemed location in memory.
- Declarition
- Initialization
4. Input & Output
std::cout <<
std::cin >>
5. Debugging
Two kind of errors:
- Compiling errors: raised by the compiler, generally resulting from violation of syntax rule or misuse of types.
- Runtime errors: Only spot when you run the program. It doesn't do what you want to do. These are more tricky.
6. Terminal Command (MacOS)
Username@MacName ~ % g++ -Wall main.cpp -o main.out
Username@MacName ~ % ./main.out