亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Algorithms Algorithms(算法) bsearch bsearch_s qsort qsort_s Atomic operations Atomic operations library(原子操作庫(kù)) ATOMIC_*_LOCK_FREE atomic_compare_exchange_strong atomic_compare_exchange_strong_explicit atomic_compare_exchange_weak atomic_compare_exchange_weak_explicit atomic_exchange atomic_exchange_explicit atomic_fetch_add atomic_fetch_add_explicit atomic_fetch_and atomic_fetch_and_explicit atomic_fetch_or atomic_fetch_or_explicit atomic_fetch_sub atomic_fetch_sub_explicit atomic_fetch_xor atomic_fetch_xor_explicit atomic_flag atomic_flag_clear atomic_flag_clear_explicit ATOMIC_FLAG_INIT atomic_flag_test_and_set atomic_flag_test_and_set_explicit atomic_init atomic_is_lock_free atomic_load atomic_load_explicit atomic_signal_fence atomic_store atomic_store_explicit atomic_thread_fence(線程圍欄) ATOMIC_VAR_INIT kill_dependency memory_order(內(nèi)存排序) C keywords auto(自動(dòng)存儲(chǔ)) break(跳出循環(huán)) C keywords(關(guān)鍵詞) case char const(常量修飾符) continue default(預(yù)設(shè)運(yùn)算式) do double(雙精度浮點(diǎn)型) else enum(枚舉類型) extern(全局變量) float(浮點(diǎn)數(shù)) for fortran goto(goto語句) if(if語句) inline(行內(nèi)函式) int long(長(zhǎng)整型) register(寄存器變量) restrict( restrict類型限定符) return short signed sizeof(sizeof運(yùn)算符) static(靜態(tài)變量) struct(結(jié)構(gòu)體) switch(switch語句) typedef(typedef關(guān)鍵字) union(聯(lián)合體) unsigned(無符號(hào)) void(空類型) volatile(volatile變量) while(while語句) _Alignas _Alignof _Atomic _Bool _Complex _Generic _Imaginary _Noreturn _Static_assert _Thread_local C language #define directive #elif directive #else directive #endif directive #error directive #if directive #ifdef directive #ifndef directive #include directive #line directive #pragma directive alignas(對(duì)齊指定符) Alternative operators and tokens(替代運(yùn)算符和令牌) Analyzability Arithmetic operators Arithmetic types Array declaration(數(shù)組聲明) Array initialization(陣列初始化) ASCII Chart Assignment operators(賦值運(yùn)算符) types(atomic類型限定符) Basic concepts Bit fields(位域) break statement C language C Operator Precedence cast operator character constant(字符字面量) Comments(注釋符) Comparison operators(比較運(yùn)算符) compound literals(符合字面量) Conditional inclusion(條件包含) Conformance(一致性) const type qualifier(const 限定符) Constant expressions(常量表達(dá)) continue statement Declarations(聲明) do-while loop Enumerations(枚舉類型) Escape sequences(轉(zhuǎn)義字符) Expressions(表達(dá)式) External and tentative definitions(外部和暫定的定義) File scope(文件范圍) floating constant(浮點(diǎn)常量) for loop Function declarations(函數(shù)聲明) Function definitions(函數(shù)聲明) Functions Generic selection泛型選擇 goto statement Identifier(標(biāo)示符) if statement Implicit conversions(隱式轉(zhuǎn)換) Increment/decrement operators(前置/后置操作符) Initialization(初始化) inline function specifier(內(nèi)聯(lián)函式) integer constant Lifetime(生命期) Logical operators(邏輯運(yùn)算符) Lookup and name spaces Main function(主函式) Member access operators(會(huì)員接入運(yùn)營(yíng)商) Memory model Objects and alignment(字節(jié)對(duì)齊) Order of evaluation(評(píng)估順序) Other operators Phases of translation(翻譯階段) Pointer declaration Preprocessor(預(yù)處理) restrict type qualifier(restrict類型限定符) return statement Scalar initialization(標(biāo)量類型初始化) Scope(范圍) sizeof operator(sizeof運(yùn)算符) Statements(陳述) static assert declaration(靜態(tài)斷言聲明) Static storage duration(靜態(tài)存儲(chǔ)周期) Storage-class specifiers(存儲(chǔ)類說明符) string literals(字符串字面量) Struct and union initialization(結(jié)構(gòu)體與聯(lián)合體初始化) Struct declaration(結(jié)構(gòu)體聲明) switch statement Thread storage duration(線程存儲(chǔ)時(shí)間) Type Type(類型) Typedef declaration(Typedef聲明) Undefined behavior(未定義行為) Union declaration(聯(lián)合體聲明) Value categories(值類別) Variadic arguments(變長(zhǎng)參數(shù)宏) volatile type qualifier(volatile 類型限定符) while loop _Alignof operator _Noreturn function specifier Date and time asctime(asctime函數(shù)) asctime_s clock CLOCKS_PER_SEC clock_t ctime(ctime函數(shù)) ctime_s Date and time utilities(日期和時(shí)間庫(kù)) difftime(計(jì)算兩個(gè)時(shí)間的間隔) gmtime gmtime_s localtime localtime_s mktime(將時(shí)間結(jié)構(gòu)數(shù)據(jù)轉(zhuǎn)換成經(jīng)過的秒數(shù)的函數(shù)) strftime(格式化輸出時(shí)間函數(shù)) time timespec timespec_get time_t tm wcsftime(格式化時(shí)間寬字符) Dynamic memory management aligned_alloc C memory management library(內(nèi)存管理庫(kù)) calloc free(釋放動(dòng)態(tài)分配空間的函數(shù)) malloc(動(dòng)態(tài)分配內(nèi)存空間的函數(shù)) realloc(重新分配內(nèi)存空間的函數(shù)) Error handling abort_handler_s assert(斷言) constraint_handler_t errno(錯(cuò)誤報(bào)告) Error handling(錯(cuò)誤處理) Error numbers(錯(cuò)誤個(gè)數(shù)) ignore_handler_s set_constraint_handler_s static_assert File input/output clearerr(清除/復(fù)位) fclose feof ferror fflush(清空文件緩沖區(qū)) fgetc fgetpos fgets fgetwc fgetws File input/output fopen fopen_s fprintf fprintf_s fputc fputs fputwc fputws fread freopen freopen_s fscanf fscanf_s fseek fsetpos ftell fwide fwprintf fwprintf_s fwrite fwscanf fwscanf_s getc getchar gets gets_s getwchar perror printf printf_s putc putchar puts putwc putwchar remove rename rewind scanf scanf_s setbuf setvbuf snprintf sprintf sscanf sscanf_s swprintf swprintf_s swscanf swscanf_s tmpfile tmpfile_s tmpnam tmpnam_s ungetc ungetwc vfprintf vfprintf_s vfscanf vfscanf_s vfwprintf vfwprintf_s vfwscanf vfwscanf_s vprintf vprintf_s vscanf vscanf_s vsnprintf vsprintf vsscanf vsscanf_s vswprintf vswprintf_s vswscanf vswscanf_s vwprintf vwprintf_s vwscanf vwscanf_s wprintf wprintf_s wscanf wscanf_s Localization support lconv LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME localeconv Localization support setlocale Numerics abs acos acosf acosh acoshf acoshl acosl asin asinf asinh asinhf asinhl asinl atan atan2 atan2f atan2l atanf atanh atanhf atanhl atanl cabs cabsf cabsl cacos cacosf cacosh cacoshf cacoshl cacosl carg cargf cargl casin casinf casinh casinhf casinhl casinl catan catanf catanh catanhf catanhl catanl cbrt cbrtf cbrtl ccos ccosf ccosh ccoshf ccoshl ccosl ceil ceilf ceill cexp cexpf cexpl cimag cimagf cimagl clog clogf clogl CMPLX CMPLXF CMPLXL Common mathematical functions complex Complex number arithmetic conj conjf conjl copysign copysignf copysignl cos cosf cosh coshf coshl cosl cpow cpowf cpowl cproj cprojf cprojl creal crealf creall csin csinf csinh csinhf csinhl csinl csqrt csqrtf csqrtl ctan ctanf ctanh ctanhf ctanhl ctanl div double_t erf erfc erfcf erfcl erff erfl exp exp2 exp2f exp2l expf expl expm1 expm1f expm1l fabs fabsf fabsl fdim feclearexcept fegetenv fegetexceptflag fegetround feholdexcept feraiseexcept fesetenv fesetexceptflag fesetround fetestexcept feupdateenv FE_ALL_EXCEPT FE_DFL_ENV FE_DIVBYZERO FE_DOWNWARD FE_INEXACT FE_INVALID FE_OVERFLOW FE_TONEAREST FE_TOWARDZERO FE_UNDERFLOW FE_UPWARD Floating-point environment float_t floor floorf floorl fma fmaf fmal fmax fmaxf fmaxl fmin fminf fminl fmod fmodf fmodl fpclassify FP_INFINITE FP_NAN FP_NORMAL FP_SUBNORMAL FP_ZERO frexp frexpf frexpl HUGE_VAL HUGE_VALF HUGE_VALL hypot hypotf hypotl I ilogb ilogbf ilogbl imaginary imaxabs imaxdiv INFINITY isfinite isgreater isgreaterequal isinf isless islessequal islessgreater isnan isnormal isunordered labs ldexp ldexpf ldexpl ldiv lgamma lgammaf lgammal llabs lldiv llrint llrintf llrintl llround llroundf llroundl log log10 log10f log10l log1p log1pf log1pl log2 log2f log2l logb logbf logbl logf logl lrint lrintf lrintl lround lroundf lroundl MATH_ERREXCEPT math_errhandling MATH_ERRNO modf modff modfl nan NAN nanf nanl nearbyint nearbyintf nearbyintl nextafter nextafterf nextafterl nexttoward nexttowardf nexttowardl Numerics pow powf powl Pseudo-random number generation rand RAND_MAX remainder remainderf remainderl remquo remquof remquol rint rintf rintl round roundf roundl scalbln scalblnf scalblnl scalbn scalbnf scalbnl signbit sin sinf sinh sinhf sinhl sinl sqrt sqrtf sqrtl srand tan tanf tanh tanhf tanhl tanl tgamma tgammaf tgammal trunc truncf truncl Type-generic math _Complex_I _Imaginary_I Program support abort atexit at_quick_exit exit EXIT_FAILURE EXIT_SUCCESS getenv getenv_s jmp_buf longjmp Program support utilities quick_exit raise setjmp SIGABRT SIGFPE SIGILL SIGINT signal SIGSEGV SIGTERM sig_atomic_t SIG_DFL SIG_ERR SIG_IGN system _Exit Strings atof atoi atol atoll btowc c16rtomb c32rtomb char16_t char32_t isalnum isalpha isblank iscntrl isdigit isgraph islower isprint ispunct isspace isupper iswalnum iswalpha iswblank iswcntrl iswctype iswdigit iswgraph iswlower iswprint iswpunct iswspace iswupper iswxdigit isxdigit mblen mbrlen mbrtoc16 mbrtoc32 mbrtowc mbsinit mbsrtowcs mbsrtowcs_s mbstate_t mbstowcs mbstowcs_s mbtowc memchr memcmp memcpy memcpy_s memmove memmove_s memset memset_s Null-terminated byte strings Null-terminated multibyte strings Null-terminated wide strings strcat strcat_s strchr strcmp strcoll strcpy strcpy_s strcspn strerror strerrorlen_s strerror_s Strings library strlen strncat Thread support call_once cnd_broadcast cnd_destroy cnd_init cnd_signal cnd_timedwait cnd_wait mtx_destroy mtx_init mtx_lock mtx_plain mtx_recursive mtx_timed mtx_timedlock mtx_trylock mtx_unlock once_flag ONCE_FLAG_INIT thrd_busy thrd_create thrd_current thrd_detach thrd_equal thrd_error thrd_exit thrd_join thrd_nomem thrd_sleep thrd_success thrd_timedout thrd_yield Thread support library thread_local tss_create tss_delete TSS_DTOR_ITERATIONS tss_get tss_set Type support Boolean type support library Fixed width integer types FLT_EVAL_METHOD FLT_ROUNDS max_align_t NULL Numeric limits offsetof ptrdiff_t size_t Type support Variadic functions Variadic functions va_arg va_copy va_end va_list va_start
characters

算術(shù)運(yùn)算符將標(biāo)準(zhǔn)的數(shù)學(xué)運(yùn)算應(yīng)用于其操作數(shù)。

Operator

Operator name

Example

Result

+

unary plus

+a

the value of a after promotions

-

unary minus

-a

the negative of a

+

addition

a + b

the addition of a and b

-

subtraction

a - b

the subtraction of b from a

*

product

a * b

the product of a and b

/

division

a / b

the division of a by b

%

modulo

a % b

the remainder of a divided by b

~

bitwise NOT

~a

the bitwise NOT of a

&

bitwise AND

a & b

the bitwise AND of a and b

|

bitwise OR

a | b

the bitwise OR of a and b

^

bitwise XOR

a ^ b

the bitwise XOR of a and b

<<

bitwise left shift

a << b

a left shifted by b


bitwise right shift

a >> b

a right shifted by b

溢出

無符號(hào)整數(shù)運(yùn)算總是以模2n 來執(zhí)行

其中 n 是該特定整數(shù)中的位數(shù)。例如unsigned int,添加一個(gè)UINT_MAX給出0,并從0給出中減去一個(gè)UINT_MAX。

當(dāng)有符號(hào)整數(shù)算術(shù)運(yùn)算溢出(結(jié)果不適合結(jié)果類型)時(shí),行為是未定義的:它可能會(huì)根據(jù)表示規(guī)則(通常是2的補(bǔ)碼)進(jìn)行回繞,它可能陷入某些平臺(tái)或由于編譯器選項(xiàng)(例如-ftrapv在 GCC 和 Clang中),或者可以由編譯器完全優(yōu)化。

浮點(diǎn)環(huán)境

如果   #pragma STDC FENV_ACCESS設(shè)置為ON,所有浮點(diǎn)算術(shù)運(yùn)算符服從當(dāng)前浮點(diǎn)舍入方向并報(bào)告 math_errhandling 中指定的浮點(diǎn)算術(shù)錯(cuò)誤,除非部分靜態(tài)初始化程序(在這種情況下不引發(fā)浮點(diǎn)異常并舍入)模式是最近的)。

浮點(diǎn)收縮

除非#pragma STDC FP_CONTRACT設(shè)置為OFF,否則   所有浮點(diǎn)運(yùn)算都可以像中間結(jié)果具有無限范圍和精度一樣執(zhí)行,即忽略舍入錯(cuò)誤和浮點(diǎn)異常(如果表達(dá)式完全按寫入方式計(jì)算)時(shí)可以觀察到的優(yōu)化。例如,允許(x*y) + z使用單個(gè)融合乘加CPU指令或優(yōu)化a = x*x*x*x;as執(zhí)行tmp = x*x; a = tmp*tmp。

與浮點(diǎn)運(yùn)算無關(guān),浮點(diǎn)運(yùn)算的中間結(jié)果的范圍和精度可能與其類型所指示的不同,請(qǐng)參閱FLT_EVAL_METHOD

一元算術(shù)

一元算術(shù)運(yùn)算符表達(dá)式具有這種形式。

  • expression

(1)


  • expression

(2)


1)一元加(促銷)

2)一元減號(hào)(否定)

其中

expression

-

expression of any arithmetic type

一元加號(hào)和一元減號(hào)首先將積分促銷應(yīng)用于它們的操作數(shù),然后。

  • 一元加值返回提升后的值

  • 一元減號(hào)返回提升后的值的負(fù)數(shù)(除了 NaN 的負(fù)數(shù)是另一個(gè) NaN)

表達(dá)式的類型是升級(jí)后的類型,值類別是非左值。

筆記

當(dāng)應(yīng)用于,或在典型(2的補(bǔ)碼)平臺(tái)上時(shí)INT_MIN,由于有符號(hào)整數(shù)溢出,一元減法調(diào)用未定義的行為。LONG_MINLLONG_MIN

在 C ++中,一元運(yùn)算符+也可以與其他內(nèi)置類型(如數(shù)組和函數(shù))一起使用,而在 C 中則不是這樣。

#include <stdio.h>#include <complex.h>int main(void){
    char c = 'a';    printf("sizeof char: %zu sizeof int: %zu\n", sizeof c, sizeof +c); 
    printf("-1, where 1 is signed: %d\n", -1);    printf("-1, where 1 is unsigned: %u\n", -1u);
 
    double complex z = 1 + 2*I;    printf("-(1+2i) = %.1f%+.1f\n", creal(-z), cimag(-z));}

可能的輸出:

sizeof char: 1 sizeof int: 4-1, where 1 is signed: -1-1, where 1 is unsigned: 4294967295-(1+2i) = -1.0-2.0

添加操作符

二元附加算術(shù)運(yùn)算符表達(dá)式具有這種形式。

lhs + rhs

(1)


lhs - rhs

(2)


1)另外:lhs 和 rhs 必須是以下之一

  • 都有算術(shù)類型,包括復(fù)雜和想象

  • 一個(gè)是完成對(duì)象類型的指針,另一個(gè)是整數(shù)類型

2)減法:lhs 和 rhs 必須是以下之一

  • 都有算術(shù)類型,包括復(fù)雜和想象

  • lhs具有完成對(duì)象類型的指針,rhs具有整數(shù)類型

  • 都是指向兼容類型的完整對(duì)象的指針,忽略限定符

算術(shù)加法和減法

如果兩個(gè)操作數(shù)都有算術(shù)類型,那么。

  • 首先,執(zhí)行通常的算術(shù)轉(zhuǎn)換

  • 然后,按照通常的數(shù)學(xué)規(guī)則(對(duì)于減法,將rhs從lhs中減去),對(duì)轉(zhuǎn)換后的操作數(shù)的值進(jìn)行相加或相減,除了

    • 如果一個(gè)操作數(shù)是 NaN,那么結(jié)果是NaN

    • 無窮大減去無窮大是 NaN 并且FE_INVALID被提升

    • 無限加上負(fù)的無窮大是 NaN 并且FE_INVALID被提升

復(fù)數(shù)和虛數(shù)加法和減法的定義如下(注意,如果兩個(gè)操作數(shù)都是虛數(shù),則結(jié)果類型為虛數(shù),如果一個(gè)操作數(shù)是實(shí)數(shù)而另一個(gè)虛數(shù),則如通常的算術(shù)轉(zhuǎn)換所指定的那樣):

  • or -

u

iv

u + iv

x

x ± u

x ± iv

(x ± u) ± iv

iy

±u + iy

i(y ± v)

±u + i(y ± v)

x + iy

(x ± u) + iy

x + i(y ± v)

(x ± u) + i(y ± v)

// work in progress// note: take part of the c/language/conversion example

指針?biāo)阈g(shù)

  • 如果指針P指向具有索引的數(shù)組的元素I,則

    • P+N并且N+P是指向具有索引的相同數(shù)組的元素的指針I+N

    • P-N 是一個(gè)指向索引{tt | IN}}的相同數(shù)組元素的指針

只有在原始指針和結(jié)果指針都指向同一數(shù)組的元素或超過該數(shù)組的末尾時(shí),才會(huì)定義行為。請(qǐng)注意,當(dāng)p指向數(shù)組的第一個(gè)元素時(shí)執(zhí)行p-1是未定義的行為,并可能在某些平臺(tái)上失敗。

  • 如果指針P1指向一個(gè)數(shù)組中的索引I(或者一個(gè)超過末尾的數(shù)組)P2的元素并且指向具有索引的相同數(shù)組的元素J(或者指向末尾的一個(gè)元素),那么

    • P1-P2具有等于的值J-I和類型ptrdiff_t(這是一個(gè)有符號(hào)的整數(shù)類型,通常是可以聲明的最大對(duì)象的大小的一半)

The behavior is defined only if the result fits in ptrdiff_t.

為了進(jìn)行指針運(yùn)算,指向不是任何數(shù)組元素的對(duì)象的指針將被視為指向大小為1的數(shù)組的第一個(gè)元素的指針。

// work in progressint n = 4, m = 3;int a[n][m];     // VLA of 4 VLAs of 3 ints eachint (*p)[m] = a; // p == &a[0] p = p + 1;       // p == &a[1] (pointer arithmetic works with VLAs just the same)(*p)[2] = 99;    // changes a[1][2]

乘法運(yùn)算符

二進(jìn)制乘法算術(shù)運(yùn)算符表達(dá)式具有這種形式。

lhs * rhs

(1)


lhs / rhs

(2)


lhs % rhs

(3)


1)乘法。lhs 和 rhs 必須有算術(shù)類型

2)division。lhs 和 rhs 必須有算術(shù)類型

3)余數(shù)。lhs 和 rhs 必須具有整數(shù)類型

  • 首先,執(zhí)行通常的算術(shù)轉(zhuǎn)換。然后...

Multiplication

二進(jìn)制運(yùn)算符*在通常的算術(shù)定義之后執(zhí)行其操作數(shù)的乘法(在通常的算術(shù)轉(zhuǎn)換之后),除此之外。

  • 如果一個(gè)操作數(shù)是 NaN,則結(jié)果是 NaN

  • 如果無窮大乘以零,就會(huì)產(chǎn)生NaN并被FE_INVALID提升

  • 無窮乘以非零乘法給無窮(即使對(duì)于復(fù)雜的參數(shù))

因?yàn)樵贑中,任何具有至少一個(gè)無限部分的復(fù)數(shù)值作為無窮大,即使其另一部分是NaN,通常的算術(shù)規(guī)則也不適用于復(fù)數(shù)復(fù)數(shù)乘法。浮點(diǎn)操作數(shù)的其他組合遵循下表:

*

u

iv

u + iv

x

xu

i(xv)

(xu) + i(xv)

iy

i(yu)

?yv

(?yv) + i(yu)

x + iy

(xu) + i(yu)

(?yv) + i(xv)

special rules

除無限處理外,不允許復(fù)數(shù)乘法溢出中間結(jié)果,除非   #pragma STDC CX_LIMITED_RANGE設(shè)置為ON,在這種情況下,可以按照(x + iy)×(u + iv)=(xu-yv)+ i (yu + xv),因?yàn)槌绦騿T承擔(dān)限制操作數(shù)范圍和處理無窮大的責(zé)任。

盡管不允許不適當(dāng)?shù)囊绯觯珡?fù)雜的乘法可能會(huì)引發(fā)虛假的浮點(diǎn)異常(否則實(shí)現(xiàn)非溢出版本非常困難)。

Division

除了那個(gè)之外,二元運(yùn)算符/第一操作數(shù)除以第二操作數(shù)(在通常的算術(shù)轉(zhuǎn)換之后)遵循通常的算術(shù)定義。

  • 當(dāng)通常的算術(shù)轉(zhuǎn)換后的類型是一個(gè)整數(shù)類型時(shí),結(jié)果是代數(shù)商(不是分?jǐn)?shù)),在實(shí)現(xiàn)定義的方向上舍入(直到C99)向零截?cái)啵ㄒ驗(yàn)镃99)

  • 如果一個(gè)操作數(shù)是NaN,則結(jié)果是NaN

  • 如果第一個(gè)操作數(shù)是復(fù)數(shù)無窮大,第二個(gè)操作數(shù)是有限的,那么

/運(yùn)算符的結(jié)果是一個(gè)復(fù)雜的無窮大。

  • 如果第一個(gè)操作數(shù)是有限的,第二個(gè)操作數(shù)是一個(gè)復(fù)數(shù)的無窮大,那么

/運(yùn)算符的結(jié)果是零。

因?yàn)樵贑中,任何具有至少一個(gè)無限部分的復(fù)數(shù)值作為無窮大,即使其另一部分是NaN,通常的算術(shù)規(guī)則也不適用于復(fù)數(shù)復(fù)數(shù)除法。浮點(diǎn)操作數(shù)的其他組合遵循下表:

/

u

iv

x

x/u

i(?x/v)

iy

i(y/u)

y/v

x + iy

(x/u) + i(y/u)

(y/v) + i(?x/v)

除無限處理外,復(fù)數(shù)除法不允許溢出中間結(jié)果,除非   #pragma STDC CX_LIMITED_RANGE設(shè)置為ON,在這種情況下,可以按照(x + iy)/(u + iv)=(xu + yv)+ i (宇-15)/(U2

+ v2

),因?yàn)槌绦騿T承擔(dān)限制操作數(shù)范圍和處理無窮大的責(zé)任。

盡管不允許不適當(dāng)?shù)囊绯?,?fù)雜的劃分可能會(huì)引發(fā)虛假的浮點(diǎn)異常(否則實(shí)現(xiàn)非溢出版本非常困難)。

如果第二個(gè)操作數(shù)為零,則行為是未定義的,但是如果支持 IEEE 浮點(diǎn)算術(shù)并且發(fā)生浮點(diǎn)除法,那么。

  • 將非零數(shù)字除以±0.0會(huì)給出正確符號(hào)的無窮大,并將FE_DIVBYZERO其升高

  • 將0.0除0.0得到NaN并FE_INVALID升高

二元運(yùn)算符%產(chǎn)生第一個(gè)操作數(shù)除以第二個(gè)操作數(shù)的其余部分(在通常的算術(shù)轉(zhuǎn)換后)。

余數(shù)的符號(hào)是這樣定義的,即如果商a/b可以在結(jié)果類型中表示,那么(a/b)*b + a%b == a。

如果第二個(gè)操作數(shù)為零,則行為未定義。

如果商a/b不能在結(jié)果類型可表示,雙方的行為a/b,并a%b沒有定義(這意味著INT_MIN%-1是未定義2的補(bǔ)數(shù)系統(tǒng))。

注意:余數(shù)運(yùn)算符不適用于浮點(diǎn)類型,庫(kù)函數(shù)fmod提供該功能。

#include<stdio.h>#include <stdio.h>#include <complex.h>#include <math.h>int main(void){ 
 // TODO simpler cases, take some from C++
 
 
   double complex z = (1 + 0*I) * (INFINITY + I*INFINITY);// textbook formula would give// (1+i0)(∞+i∞) ? (1×∞ – 0×∞) + i(0×∞+1×∞) ? NaN + I*NaN// but C gives a complex infinity   printf("%f + i*%f\n", creal(z), cimag(z)); // textbook formula would give// cexp(∞+iNaN) ? exp(∞)×(cis(NaN)) ? NaN + I*NaN// but C gives  ±∞+i*nan
   double complex y = cexp(INFINITY + I*NAN);   printf("%f + i*%f\n", creal(y), cimag(y)); }

可能的輸出:

inf + i*inf 
inf + i*nan

按位邏輯

按位算術(shù)運(yùn)算符表達(dá)式具有這種形式。

~ rhs

(1)


lhs & rhs

(2)


lhs | rhs

(3)


lhs ^ rhs

(4)


1) bitwise NOT

2) bitwise AND

3) bitwise OR

4) bitwise XOR

其中

lhs, rhs

-

expressions of integer type

首先,運(yùn)營(yíng)商&,^和| 對(duì)兩個(gè)操作數(shù)執(zhí)行通常的算術(shù)轉(zhuǎn)換操作符?對(duì)其唯一的操作數(shù)執(zhí)行整數(shù)提升。

然后,相應(yīng)的二進(jìn)制邏輯運(yùn)算符按位進(jìn)行應(yīng)用; 也就是說,根據(jù)邏輯操作(NOT,AND,OR 或 XOR)將結(jié)果的每一位置1或清零,并將其應(yīng)用于操作數(shù)的相應(yīng)位。

注意:位運(yùn)算符通常用于操作位集和位掩碼。

注意:對(duì)于無符號(hào)類型(推廣后),表達(dá)式?E等于結(jié)果類型可表示的最大值減去E的原始值。

#include <stdio.h>#include <stdint.h>int main(void){
    uint16_t mask = 0x00f0;
    uint32_t a = 0x12345678;    printf("Value: %#x mask: %#x\n"           "Setting bits:   %#x\n"           "Clearing bits:  %#x\n"           "Selecting bits: %#x\n",
           a,mask,(a|mask),(a&~mask),(a&mask));}

可能的輸出:

Value: 0x12345678 mask: 0xf0Setting bits:   0x123456f8Clearing bits:  0x12345608Selecting bits: 0x70

移位操作

按位移運(yùn)算符表達(dá)式具有這種形式。

lhs << rhs

(1)


lhs >> rhs

(2)


1)左移 rhs 位

2)通過 rhs 位右移 lhs

其中

lhs, rhs

-

expressions of integer type

首先,對(duì)每個(gè)操作數(shù)單獨(dú)執(zhí)行整數(shù)升級(jí)(注意:這不同于其他二進(jìn)制算術(shù)運(yùn)算符,它們都執(zhí)行常規(guī)算術(shù)轉(zhuǎn)換)。結(jié)果的類型是促銷后的 lhs 類型。

對(duì)于無符號(hào)的 lhs,其值LHS << RHS是 LHS * 2RHS 的值

返回類型的模數(shù)最大值減1加(即,執(zhí)行按位左移,并且丟棄從目標(biāo)類型移出的位)。對(duì)于有符號(hào)的 lhs,其值為LHS << RHSLHS * 2RHS

如果它在升級(jí)類型的 lhs 中可表示,否則行為是未定義的。

對(duì)于無符號(hào)的 lhs 和帶有非負(fù)值的帶符號(hào)的 lhs,其值LHS >> RHS是 LHS / 2RHS 的整數(shù)部分

對(duì)于負(fù)數(shù)LHS,值LHS >> RHS是實(shí)現(xiàn)定義的,在大多數(shù)實(shí)現(xiàn)中,這將執(zhí)行算術(shù)右移(以便結(jié)果保持負(fù)值)。因此,在大多數(shù)實(shí)現(xiàn)中,向右移位一個(gè)符號(hào)LHS將使用原始符號(hào)位填充新的較高位(即,如果它是非負(fù)的則為0,如果是負(fù)的則為0)。

在任何情況下,如果 rhs 為負(fù)數(shù)或者大于或等于升級(jí)的 lhs 中的位數(shù),則行為是不確定的。

#include <stdio.h>enum {ONE=1, TWO=2};int main(void){
    char c = 0x10;
    unsigned long long ulong_num = 0x123;    printf("0x123 << 1  = %#llx\n"           "0x123 << 63 = %#llx\n"   // overflow truncates high bits for unsigned numbers           "0x10  << 10 = %#x\n",    // char is promoted to int
           ulong_num << 1, ulong_num << 63, c << 10);
    long long long_num = -1000;    printf("-1000 >> 1 = %lld\n", long_num >> ONE);  // implementation defined}

可能的輸出:

0x123 << 1  = 0x2460x123 << 63 = 0x80000000000000000x10  << 10 = 0x4000-1000 >> 1 = -500
Previous article: Next article: