C LANGUAGE TUTORIAL LESSON 3 MORE DATA TYPES









- Slides: 9

C++ LANGUAGE TUTORIAL LESSON 3 – MORE DATA TYPES & OPERATORS • • • More data types More operators Boolean Equality operators Logical operators

More Data Types • Int’s can be unsigned and/or long or short • Unsigned means there are only positive numbers, but this can be a larger number • Long means more space is allowed for the value, so it can be larger, short makes it smaller

Example • int takes 4 bytes of space, number range is: signed: 2147483648 to 2147483647 unsigned: 0 to 4294967295 • short int takes 2 bytes of space, number range is: signed: 32768 to 32767 unsigned: 0 to 65535 It turns out that long int is the same as int.

Some More Operators • ‘++’ Increment operator, adds 1 to the value • Can be used before or after a numeric variable • Used before is called pre-increment, the operator takes effect before any other operation • Used after is called post-increment, the operator takes effect after any other operation • ‘--’ Decrement operator, subtracts 1 from the value

Boolean bool type. A Logical data type. Can be either true or false • Or 1 of 0 • Stored in a single Byte, but only needs 1 bit • Is returned by comparison operations

Equality Operators ‘==‘ returns true if both operands are identical ‘!=‘ returns true if both operands are not equal ‘<‘ returns true if the left operand is less than the right operand ‘<=‘returns true if the left operand is less than or equal to the right operand ‘>‘returns true if the left operand is greater than or equal to the right operand ‘>=‘returns true if the left operand is greater than or equal to the right operand

Logical Operators Performs logical comparisons • Return either true or false • and, or, and not • In C++, these are &&, ||, !

Combining Equality Operators • Equality operators can be combined using logic operators • For example: 5 > 4 && 3 < 7 • This would return true • Use brackets to ensure the correct precedence – e. g. a && (b || c)

The end That concludes are last lesson you should now understand Boolean and the operators that Go with bool types along with the equality operators and understand the difference Between signed int and unsigned int. As allways the source code for the demonstration with fully explained comments (more extensive than the video), along with the execution able file is available on the site for download.