C與C++的敘述
C是作為一種中間語言,即介於進階商業應用程式語言如COBOL,以及直達機器、高性能但是不易於使用的組合語言。C是要實作結構化的程式設計,這種方法將問題分解為較小且可重覆的單元,叫作程序。
C++是作為一個物件導向程式設計方法和C之間的橋梁而創立的,是世界上最流行的商業軟體發展設計語言。其目標就是為了將物件導向的設計方法提供給快速、商業化的軟體發展作為一種平台。
How about JAVA ?
How about Android ?
How about UML ?
2015年3月29日 星期日
2015年3月26日 星期四
[Linux_C]004
來源為wiki的Operators in C and C++
方便未來 重載運算子 用
關於C++ operator介紹如下:
方便未來 重載運算子 用
關於C++ operator介紹如下:
Arithmetic operators | |||||
Operator name
|
Syntax
|
Can overload
|
Included
in C | Prototype examples | |
As member of K | |||||
Basic assignment | a = b | Yes | Yes | R& K::operator =(S b); | |
Addition | a + b | Yes | Yes | R K::operator +(S b); | |
Subtraction | a - b | Yes | Yes | R K::operator -(S b); | |
Unary plus (integer promotion) | +a | Yes | Yes | R K::operator +(); | |
Unary minus (additive inverse) | -a | Yes | Yes | R K::operator -(); | |
Multiplication | a * b | Yes | Yes | R K::operator *(S b); | |
Division | a / b | Yes | Yes | R K::operator /(S b); | |
Modulo (integer remainder) | a % b | Yes | Yes | R K::operator %(S b); | |
Increment
| Prefix | ++a | Yes | Yes | R& K::operator ++(); |
Postfix
|
a++
|
Yes
|
Yes
| R K::operator ++(int); | |
Note: C++ uses the unnamed dummy-parameter int to differentiate between prefix and suffix increment operators. | |||||
Decrement
| Prefix | --a | Yes | Yes | R& K::operator --(); |
Postfix
|
a--
|
Yes
|
Yes
| R K::operator --(int); | |
"Note: C++ uses the unnamed dummy-parameter int to differentiate between prefix and suffix decrement operators." | |||||
Comparison operators/relational operators | |||||
Operator name
|
Syntax
|
Can overload
|
Included
in C | Prototype examples | |
As member of K | |||||
Equal to | a == b | Yes | Yes | bool K::operator ==(S const& b); | |
Not equal to | a != b a not_eq b | Yes | Yes | bool K::operator !=(S const& b); | |
Greater than | a > b | Yes | Yes | bool K::operator >(S const& b); | |
Less than | a < b | Yes | Yes | bool K::operator <(S const& b); | |
Greater than or equal to | a >= b | Yes | Yes | bool K::operator >=(S const& b); | |
Less than or equal to | a <= b | Yes | Yes | bool K::operator <=(S const& b); | |
Logical operators | |||||
Operator name
|
Syntax
|
Can overload
|
Included
in C | Prototype examples | |
As member of K | |||||
Logical negation (NOT) | !a not a | Yes | Yes | R K::operator !(); | |
Logical AND | a && b a and b | Yes | Yes | R K::operator &&(S b); | |
Logical OR | a || b a or b | Yes | Yes | R K::operator ||(S b); | |
Bitwise operators | |||||
Operator name
|
Syntax
|
Can overload
|
Included
in C | Prototype examples | |
As member of K | |||||
Bitwise NOT | ~a compl a | Yes | Yes | R K::operator ~(); | |
Bitwise AND | a & b a bitand b | Yes | Yes | R K::operator &(S b); | |
Bitwise OR | a | b a bitor b | Yes | Yes | R K::operator |(S b); | |
Bitwise XOR | a ^ b a xor b | Yes | Yes | R K::operator ^(S b); | |
Bitwise left shift | a << b | Yes | Yes | R K::operator <<(S b); | |
Bitwise right shift | a >> b | Yes | Yes | R K::operator >>(S b); | |
Member and pointer operators | |||||
Operator name
|
Syntax
|
Can overload
|
Included
in C | Prototype examples | |
As member of K | |||||
Array subscript | a[b] | Yes | Yes | R& K::operator [](S b); | |
Indirection ("object pointed to by a") | *a | Yes | Yes | R& K::operator *(); | |
Address ("address of a") | &a | Yes | Yes | R K::operator &(); | |
Structure dereference ("member b of object pointed to bya") | a->b | Yes | Yes | R* K::operator ->(); | |
Structure reference ("member b of object a") | a.b | No | Yes | N/A | |
Object pointed to by member b of object pointed to by a | a->*b | Yes | No | R& K::operator ->*(S b); | |
Object pointed to by member b of object a | a.*b | No | No | N/A | |
Other operators | |||||
Operator name
|
Syntax
|
Can overload
|
Included
in C | Prototype examples | |
As member of K | |||||
Function call See Function object. | a(a1, a2) | Yes | Yes | R K::operator ()(S a, T b, ...); | |
Comma | a, b | Yes | Yes | R K::operator ,(S b); | |
Ternary conditional | a ? b : c | No | Yes | N/A | |
Scope resolution | a::b | No | No | N/A | |
User-defined literals since C++11 | "a"_b | Yes | No | N/A | |
Conversion ( C-style cast)
|
(type) a
type(a) |
Yes
|
Yes
| K::operator R(); | |
Note: for user-defined conversions, the return type implicitly and necessarily matches the operator name. | |||||
Size-of | sizeof (a) sizeof (type) | No | Yes | N/A | |
Size of parameter pack since C++11 | sizeof...(Args) | No | No | N/A | |
Align-of since C++11 | alignof (type) or _Alignof (type) | No | Yes | N/A | |
Allocate storage | new type | Yes | No | void* K::operator new(size_t x); | |
Allocate storage (array) | new type[n] | Yes | No | void* K::operator new[](size_t a); | |
Deallocate storage (delete returns void so it isn't strictly speaking an operator) | delete a | Yes | No | void K::operator delete(void *a); | |
Deallocate storage (array) | delete[] a | Yes | No | void K::operator delete[](void *a); | |
Type identification | typeid (a) typeid (type) | No | No | N/A | |
static_cast conversion | static_cast<type>(a) | No | No | N/A | |
dynamic_cast conversion | dynamic_cast<type>(a) | No | No | N/A | |
const_cast conversion | const_cast<type>(a) | No | No | N/A | |
reinterpret_cast conversion | reinterpret_cast<type>(a) | No | No | N/A | |
Exception check since C++11 | noexcept(a) | No | No | N/A |
2015年3月25日 星期三
[Linux_C]003
常見指令
常見數學函數 | ||
ceil(f) | 將 f 變為最大整數 | |
floor(f) | 將 f 變為最小整數 | |
sqrt(f) | f的平方根 | |
exp(f) | 自然指數 | |
log(f) | e為基底的自然對數 | |
log10(f) | 10為基底的自然對數 | |
pow(f,g) | f的g次方 | |
sin(f) | sin | |
cos(f) | cos | |
tan(f) | tan | |
fabs(f) | 浮點數取絕對值 | |
fmod(f,g) | 計算f/g的餘數 | |
acos,asin,atan |
其餘相關三角函數
| |
acosh,asinh,atanh | ||
cosh,sinh,tanh | ||
常見字串與字元函數 | ||
strcpy(s1,s2) | s2複製到s1,直到遇到null符號 | |
strncpy(s1,s2,n) | s2中n個字元複製到s1,直到遇到null符號 | |
strcat(s1,s2) | s2複製到s1的結尾 | |
strncat(s1,s2,n) | s2中的n個字元複製到s1的結尾 | |
strcmp(s1,s2) | s2與s1進行比較 | |
strncmp(s1,s2,n) | s2中n個字元與s1進行比較 | |
strlen(s1) | 字串長度 | |
strlwr(s1) | 轉為小寫 | |
strupr(s1) | 轉為大寫 | |
strtok(s1,s2) | 以s2分割s1中的內容 | |
strtod(s1),strtol(s1) | 轉為整數或長整數 | |
一般常見函數 | ||
system(s1) | s1作為命令對系統下指令 | |
malloc(n) | 分配n bytes記憶體 | |
free(ptr) | 釋放malloc或realloc | |
realloc(ptr,n) | 替malloc在增加n bytes | |
abs(n) | 絕對值 | |
asctime(t) | 時間 | |
bsearch() | 排序的資料進行二分法搜尋 | |
qsort() | 進行排序 | |
isalpha(c) | 是否為字母 | |
isdigit(c) | 是否為數字 | |
islower(c) | 是否為小寫 | |
isupper(c) | 是否為大寫 |
訂閱:
文章 (Atom)