Supplementary Materials-程式設計筆記
補充資料
Literal Constant
Ex:
1 2 3 4 5 6 7
| #include <iostream> using namespace std; int main(){ cout<<75<<" "<<0113<<" "<<0x4b<<"\n"; cout<<75<<" "<<75u<<" "<<75l<<" "<<75ul<<" "<<75lu<<"\n"; cout<<6.02e23<<" "<<1.6e-19<<"\n"; }
|
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"; cout<<bitset<8>(~x)<<" "<<bitset<8>(x|y)<<" "<<bitset<8>(x&y)<<" "<<bitset<8>(x^y)<<"\n"; }
|
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; }
|
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; }
|
Linked List(寒假學)