【正文】
se it without parentheses see , Composite type creation ? Aliasing names with ―typedef ‖ Form : typedef existingtypedescription aliasname Example: int* x, y。 ? enum snap { crackle = 25, pop }。 IntPtr m, n。Typeid必須是類的指針、類的引用或者 void *; 如果 typeid是類指針類型,那么 expression也必須是一個指針,如果 typeid是一個引用,那么 expression也必須是一個引用。 ? 用法: ? 常量指針被轉(zhuǎn)化成非常量指針,并且仍然指向原來的對象; 常量引用被轉(zhuǎn)換成非常量引用,并且仍然指向原來的對象; ? 常量對象被轉(zhuǎn)換成非常量對象。 ③把空指針轉(zhuǎn)換成目標類型的空指針。 Casting operators ? C++ Style-四個類型轉(zhuǎn)換符 ? static_cast ? const_cast ? reinterpret_cast ? dynamic_cast static_cast ? 用法: static_cast typeid ( expression ) 該運算符把 expression轉(zhuǎn)換為 typeid類型,但沒有運行時類型檢查來保證轉(zhuǎn)換的安全性。 Constants and volatile Whereas the qualifier const tells the piler ―This never changes‖ ,the qualifier volatile tells the piler ―You never know when this will change‖. Casting operators ? C Style ? 類型轉(zhuǎn)換操作符 (typeid) expression int b=10。 // Can39。d。i。 double d。 // ok, r3 initialized elsewhere Pointer to void ? void * : pointer to any type of object. int main() { void* vp。 // ok, r1 initialized intamp。 *ipa = 100?!?and it will produce the address of that identifier. see ―‖ ? pointer definition For a type T , T * is the type “ pointer to T”, that is , a variable of type T * can hold the address of an object of type T. Introduction to pointers ? The operator that defines a pointer ?*‘ ? Insert a star ?*‘ between the type and the identifier int* ip。 else return n * factorial(n 1)。 } Execution control statements ? 遞歸算法 ? 計算某個數(shù)的階乘就是用那個數(shù)去乘包括 1 在內(nèi)的所有比它小的數(shù)。fib(1) = 1。 } Execution control statements ? 循環(huán)結(jié)構(gòu) ? 在循環(huán)結(jié)構(gòu)中 , 程序根據(jù)判斷條件是否成立 ,來決定是否重復(fù)執(zhí)行某個程序段 。 break。也就是說,這種程序結(jié)構(gòu),能有選擇地執(zhí)行程序中的不同程序段。 Operators ? Operator precedence ? use parentheses to make the order of evaluation explicit ? A = X + Y – 2 / 2 + Z。= xamp。 (i10) || 邏輯或 c==0 || c==9 Operators ? 三元運算符 在 C++中只提供了一個三元運算符 —即條件運算符 “ ?: ” ,其一般形式為: 表達式 1 ? 表達式 2 : 表達式 3 條件運算的規(guī)則是:首先判斷表達式 1的值,若其值為真(非 0),則取表達式 2的值為整個表達式的值;若其值為假( 0),則取表達式 3的值為整個表達式的值。 % 求余 整數(shù) z=x%y ++ 自加 數(shù)值 z++或 ++z Operators ? 賦值運算符