MIT 6.096 introduction to C + + review notes


Recently, I picked up C + +. I refer to the concise course of MIT 6.096 for review. All the notes are sorted out from the course structure notes, C + + documents and related books

Course links:…

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

  • Bool
  • Integer
  • Double Doubly precise floating point number
  • Character
  • chat * A text string
  • String A 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)

[email protected] ~ % g++ -Wall main.cpp -o main.out
[email protected] ~ % ./main.out