true
and
false
.
bool
type-name.
bool is_positive(int x) if x > 0 return true else return false
|
bool is_positive(int x) return x > 0
|
false
.
true
.
Zero values convert to false
.
Non-zero values convert to true
.
false
converts to 0
.
true
converts to 1
.
if count(a, x, n) // one or more x in a. else // no x in a.
|
if count(a, x, n) != 0 // one or more x in a. else // no x in a.
|
int found = 0;bool done = false;
&&
, or ||
,
and negation !
.
|
with bang !
.
!
high, &&
, and ||
low, all lower
than most other operators.
not x > 7 && y > 7 || x + y > 14 ((((not x) > 7) && (y > 7)) || (x + y > 14))
(x <= 7 && y > 7) || (x + y > 14)
and
for &&
, or
for ||
, and not
for !
.
if !done && !is.eof() { ... } if not done and not is.eof() { ... }
and
, or
, and not
are not available as
names.
and
and or
behave almost the same way as the mathematical
and and or.
|
|
b
if
possible.
bool and(bool a, bool b) if not a return false else if b return true else return false
|
bool or(bool a, bool b) if a return true else if b return true else return false
|
while (ptr and ptr->value != x) ptr++; while (i < n and a[i] != x) i++;
b
is a function.
if x < 10 and f(x) > 20 { ... }
f()
may or may not be called.
f()
must be side-effect free (no I-O in particular).
char
type-name.
signed
and unsigned
modifiers
with char
.
typedef unsigned char byte;
long
, int
(the default), and short
.
long long
to give a true long integer.
signed
(the default) and unsigned
.
sizeof(short) <= sizeof(int) <= sizeof(long) < sizeof(long long)
Any other requirements you should establish explicitly in your program (or elsewhere).
if sizeof(long long) != 8 std::cerr "long long ints aren't eight bytes" exit(1)
typedef signed char s_1byte typedef short s_2byte typedef int s_4byte typedef long long s_8byte
i = 65535 j = 1 if (j > i) std::cerr << "?\n";
|
if (i > i + 1) std::cerr << "!\n";
|
65535
into a (signed) short sets the sign bit, turning the
value into -1
.
int
values.
int
values, if needed.
float
, double
(the default), and
long double
.
if (x > y) { ... } if (x == y) { ... }
if (x - y > 0.001) { ... } if (tabs(x - y) < 0.0001) { ... }
This page last modified on 9 September 2003.