Supplementary Materials-程式設計筆記

Shih Jiun Lin Lv4

補充資料

Literal Constant

Ex:

1
2
3
4
5
6
7
#include <iostream>
using namespace std;
int main(){
cout<<75<<" "<<0113<<" "<<0x4b<<"\n"; //Decimal, Octal, Hexadecimal
cout<<75<<" "<<75u<<" "<<75l<<" "<<75ul<<" "<<75lu<<"\n"; //int, unsigned, unsigned long, usigned long
cout<<6.02e23<<" "<<1.6e-19<<"\n"; //6.02*10^23
}

Bitwise Operators

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <bitset>
using namespace std;
int main(){
int x=0b00000001;
int y=0b00000000;
cout<<bitset<8>(x<<1)<<" "<<bitset<8>(x>>1)<<"\n"; //left / right shift for 1 bit
cout<<bitset<8>(~x)<<" "<<bitset<8>(x|y)<<" "<<bitset<8>(x&y)<<" "<<bitset<8>(x^y)<<"\n"; // not, or, and, xor
}

Dynamic Memory allocation

Reference: http://ccy.dd.ncu.edu.tw/~chen/course/Cpp/ch5/6.htm

Ex:

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;
int main(){
int *p;
p=new int;
*p=100;
cout<<*p;
delete p; //release the memory space
}

Ex2:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;
int main(){
int *p=new int [5];
for(int i=0; i<5; i++){
*(p+i)=i;
}
for(int i=0; i<5; i++){
cout<<*(p+i)<<" ";
}
delete []p; //release memory space
}

Linked List(寒假學)

  • Title: Supplementary Materials-程式設計筆記
  • Author: Shih Jiun Lin
  • Created at : 2023-01-17 23:00:50
  • Updated at : 2023-01-24 01:33:02
  • Link: https://shih-jiun-lin.github.io/2023/01/17/Supplementary Materials/
  • License: This work is licensed under CC BY-NC-SA 4.0.