Chapter 3: Variables, Data Types, and Arithmetic Expressions
Integer arithmetic
Operations on integers. Any decimals in the result are left off. ex. 25/2 = 12
Which operator acts as unary and binary?
minus (-). As unary it negates a value, as binary it subtracts two values
4 modifiers
signed, unsigned, short, long
You can omit digits ___ or ___ the decimal in a floating point value, but not both
before or after. These are all valid: 3. 125.8 -.001
4 basic arithmetic types
char, int, float, double
Unless told otherwise, all floating-point constants are taken as ____ by the compiler
double
What are the two size quantifiers?
long and short
What is the printf() format specifier for octal notation with a leading zero?
%#o
What is the printf() format specifier for hexadecimal notation with a leading 0x?
%#x
What printf specifier is used to display floats in scientific notation?
%e
What printf specifier is used to display floating-point values?
%f
What format specifier should be used to display a boolean value?
%i This will display 0 for false and 1 for true
What is the printf() format specifier for octal notation with no leading zero?
%o
What is the printf() format specifier for hexadecimal notation with no leading 0x?
%x
Example of a unary operator
- is used to negate a value
Rules for variable name
Must begin with a letter or _ and can be followed by any combination of letters, underscores, or digits 0-9
0 indicates ____, 1 indicates ____
0 = false, 1 = true
How many bytes for a char?
1
Hexadecimal is base __
16
How many bytes for a short int (aka short)?
2
What does this floating point number mean: 2.25e-3
2.25 x 10^3 or 0.00225
int x = 100.0 / 3 x=?
33 The integer cannot store decimal places so they are truncated.
How many bytes for a float?
4
What will the following code print? int i = 050; printf("%d\n", i);
40 The %d is used for decimal values, whereas i is an octal value. It is converted to decimal before printing. To keep as octal, use %o, and to keep the leading 0, use %#0
The octal numbering system is base ___
8
How many bytes for a double?
8 (double the precision of float)
How many bytes is a pointer?
8, just like a long long int
What does the %g printf specifier do?
Allows printf to decide whether to display a floating point value normally (%f) or in scientific notation (%e). This decision is based on the value of the exponent. Any trailing 0s are not displayed
What is size_t?
An alias for whatever the largest unsigned object in the system can hold. On a 32 bit system that is usually unsigned int (4 bytes, 32 bits) but on a 64 bit system it is usually unsigned long long (8 bytes, 64 bits). This is often used as the return type for functions that should return an arbitrarily large number, as it's guaranteed to support the biggest number possible.
What is a constant expression?
An expression where each term is a constant (no variables). Ex. 2 + 3 - 4
Unary operator
An operator that operates on a single value, as opposed to two values like the binary operator
What is a constant?
Any number, single character, or character string that is not composed of a variable. It never changes.
How many bytes for a long double?
At least 10, usually 12 or 16
How many bytes for a size_t?
At least 2, usually 4 (same as int)
How many bytes for a long long int?
At least 8
[T/F] Special characters are allowed in variable names
False. Only _ is allowed
What's the difference between a long int and a long
None. Int can be omitted. The same applies to short int and short, or long long int and long long
The modulus operator has the same precedence as
Multiplication and division
List the operator precedences
Same category is computed left -> right 1. Unary + and - 2. (typecast) 3. Multiplication, division, and modulus 4. Addition and subtraction
How many bytes for an int?
at least 2, but usually 4
How do you denote that a value is represented in hexadecimal?
Start it with 0x
What notation marks an integer as octal?
Starts with a 0 Ex. 050 octal = 40 decimal
What does it mean to say datatype ranges are implementation or machine-specific?
The range of values they can have is dependent on the specific computer and not the language
Why are + - * and / known as binary operators?
They operate on 2 values or terms
[T/F] '\n' is a single character
True
Assigning any nonzero value to a boolean makes it ____
True, and as such represented by a 1
(typecast)
Typecasting a value will temporarily convert it to a different type for the current operation. It does not change the type permanently.
What operator(s) has the highest precedence?
Unary - and + (for negating values)
How many bytes for a long int (aka long)?
at least 4, usually 8
Having %% in a printf string means
You actually intend to print %
What is the boolean data type in C called?
_Bool
Force the compiler to use floats instead of doubles by
appending f or F to the end of the floating point value