2015年3月29日 星期日

[Linux_C]

C與C++的敘述

C是作為一種中間語言,即介於進階商業應用程式語言如COBOL,以及直達機器、高性能但是不易於使用的組合語言。C是要實作結構化的程式設計,這種方法將問題分解為較小且可重覆的單元,叫作程序。

C++是作為一個物件導向程式設計方法和C之間的橋梁而創立的,是世界上最流行的商業軟體發展設計語言。其目標就是為了將物件導向的設計方法提供給快速、商業化的軟體發展作為一種平台。

How about JAVA ?

How about Android ?

How about UML ?

2015年3月26日 星期四

[Linux_C]004

來源為wiki的Operators in C and C++

方便未來 重載運算子
關於C++ operator介紹如下:

Arithmetic operators
Operator name
Syntax
Can overload
Included
in C
Prototype examples
As member of K
Basic assignmenta = bYesYesR& K::operator =(S b);
Additiona + bYesYesR K::operator +(S b);
Subtractiona - bYesYesR K::operator -(S b);
Unary plus (integer promotion)+aYesYesR K::operator +();
Unary minus (additive inverse)-aYesYesR K::operator -();
Multiplicationa * bYesYesR K::operator *(S b);
Divisiona / bYesYesR K::operator /(S b);
Modulo (integer remainder)a % bYesYesR K::operator %(S b);
Increment
Prefix++aYesYesR& 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--aYesYesR& 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 toa == bYesYesbool K::operator ==(S const& b);
Not equal toa != b
a not_eq b
YesYesbool K::operator !=(S const& b);
Greater thana > bYesYesbool K::operator >(S const& b);
Less thana < bYesYesbool K::operator <(S const& b);
Greater than or equal toa >= bYesYesbool K::operator >=(S const& b);
Less than or equal toa <= bYesYesbool 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
YesYesR K::operator !();
Logical ANDa && b
a and b
YesYesR K::operator &&(S b);
Logical ORa || b
a or b
YesYesR 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
YesYesR K::operator ~();
Bitwise ANDa & b
a bitand b
YesYesR K::operator &(S b);
Bitwise ORa | b
a bitor b
YesYesR K::operator |(S b);
Bitwise XORa ^ b
a xor b
YesYesR K::operator ^(S b);
Bitwise left shifta << bYesYesR K::operator <<(S b);
Bitwise right shifta >> bYesYesR K::operator >>(S b);
Member and pointer operators
Operator name
Syntax
Can overload
Included
in C
Prototype examples
As member of K
Array subscripta[b]YesYesR& K::operator [](S b);
Indirection ("object pointed to by a")*aYesYesR& K::operator *();
Address ("address of a")&aYesYesR K::operator &();
Structure dereference
("member b of object pointed to bya")
a->bYesYesR* K::operator ->();
Structure reference ("member b of object a")a.bNoYesN/A
Object pointed to by member
b of object pointed to by a
a->*bYesNoR& K::operator ->*(S b);
Object pointed to by member b of object aa.*bNoNoN/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)YesYesR K::operator ()(S a, T b, ...);
Commaa, bYesYesR K::operator ,(S b);
Ternary conditionala ? b : cNoYesN/A
Scope resolutiona::bNoNoN/A
User-defined literals
since C++11
"a"_bYesNoN/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-ofsizeof (a)
sizeof (type)
NoYesN/A
Size of parameter pack
since C++11
sizeof...(Args)NoNoN/A
Align-of
since C++11
alignof (type)
or _Alignof (type)
NoYesN/A
Allocate storagenew typeYesNovoid* K::operator new(size_t x);
Allocate storage (array)new type[n]YesNovoid* K::operator new[](size_t a);
Deallocate storage
(delete returns void so it isn't
strictly speaking an operator)
delete aYesNovoid K::operator delete(void *a);
Deallocate storage (array)delete[] aYesNovoid K::operator delete[](void *a);
Type identificationtypeid (a)
typeid (type)
NoNoN/A
static_cast conversionstatic_cast<type>(a)NoNoN/A
dynamic_cast conversiondynamic_cast<type>(a)NoNoN/A
const_cast conversionconst_cast<type>(a)NoNoN/A
reinterpret_cast conversionreinterpret_cast<type>(a)NoNoN/A
Exception check
since C++11
noexcept(a)NoNoN/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)是否為大寫
創用 CC 授權條款
我什麼都不會!!Eddie Sung製作,以創用CC 姓名標示-非商業性-相同方式分享 3.0 台灣 授權條款釋出。
此作品衍生自Eddie Sung