Alle boeken

Professioneel

Apps Over Coach Inloggen Begin met lezen

Computer Science · Begrippenlijst

Wat is Integer promotion, usual arithmetic conversions?

Ook bekend als: integer promotion · usual arithmetic conversions

Definition 2.3 University Computer Science — Year 1 · Hoofdstuk 2 — C: Types, Operators and Control Flow

The integer promotion converts an operand of a type narrower than int (char, short, their unsigned forms, bool) to int, since int can represent all their values. The usual arithmetic conversions then bring both operands of a binary operator to a common type: if either is floating, to the wider floating type. Otherwise, after promotion, with the ranks int << long << long long: (i) if both operands are signed or both unsigned, to the integer type of greater rank; (ii) if the unsigned operand has a rank greater than or equal to the other’s, to its unsigned type; (iii) if the signed operand has the greater rank, to that signed type when it can represent every value of the unsigned one, and otherwise to the unsigned type of the same rank. A signed operand converted to an unsigned type of width NN takes its value modulo 2N2^N.

Lees in het hoofdstuk →