3.1 Variables and assignments (general)

What is a variable?
A variable is a named item used to hold a value.

What does an assignment do?
An assignment assigns a variable with a value.

Note

The assignment operation in C returns the value being assigned. x = 5 returns the value 5. This allows you to do assignments like x = y = 0, which sets the value of both variables to the same value.

What does it mean to increment a variable?
To increment a variable means to increase a variable's value by 1.

3.2 Variables (int)

What is a variable declaration?
A variable declaration is a statement that declares a new variable's name and data type.

What does the compiler do when a variable is declared?
When a variable is declared, the compiler allocates a memory location capable of storing the data type of the variable.

What is the process of allocation?
The process of allocation is determining a suitable memory location to store data.

What three things does an assignment statement consist of?
The three things an assignment statement consists of are:

  • The name of the variable.
  • The assignment operator (=).
  • The expression.

What is an integer literal? (1)
An integer literal is a number whose value is written in the source code and is not the result of calculation.

What happens if you read a variable which hasn't been assigned a value?
If you read a variable which hasn't been assigned a value, the value can be an unknown number that depends on what system the program runs on.

3.3 Identifiers

What is an identifier?
An identifier is a name created by a programmer.

What are the three acceptable types of characters for an identifier?
The three acceptable types of characters for an identifier are:

  1. Letters.
  2. Underscores.
  3. Numbers.

What must identifiers start with?
Identifiers must start with a letter or underscore.

Identifiers are case ...
Identifiers are case sensitive.

What is a reserved word?
A reserved word is a word that is part of the language.

What is a reserved word also called?
A reserved word is also called a keyword.

What are the two different naming conventions for identifiers?
The two different naming conventions for identifiers are:

  1. Camel case.
  2. Underscore separated.

Good practice is to create meaningful identifier names that self-describe an item's ...
Good practice is to create meaningful identifier names that self-describe an item's purpose.

Good practice minimizes use of ... in identifiers except for well-known ones.
Good practice minimizes use of abbreviations in identifiers except for well-known ones.

3.4 Arithmetic expressions (general)

What is an expression?
An expression is any individual item or combination of items that evaluates to a value.

What is a literal?
A literal is a specific value.

What is an operator?
An operator is a symbol that performs a built-in calculation.

What are the nine arithmetic operators in C?
The nine arithmetic operators in C are:

  1. Addition (+).
  2. Subtraction (-).
  3. Multiplication (*).
  4. Division (/).
  5. Modulus (%).
  6. Increment (++).
  7. Decrement (--).
  8. Unary plus (+).
  9. Unary minus (-).

What are the precedence rules for arithmetic operators in C?
The precedence rules for arithmetic operators in C are:

  1. ().
  2. Increment (++), decrement (--).
  3. Unary -, unary +.
  4. *, /, %.
  5. +, -.
  6. Left-to-right.

3.5 Arithmetic expressions (int)

What are compound operators?
Compound operators are a shorthand way to update a variable.

3.6 Example: Health data

What is incremental development?
Incremental development is the process of writing, compiling, and testing a small amount of code at a time.

3.7 Floating-point numbers (double)

What is a floating-point number?
A floating-point number is a real number containing a decimal point.

What is a double?
A double is a variable which stores a floating-point number.

What is a floating-point literal?
A floating-point literal is a number with a fractional part whose value is written in the source code and is not the result of a calculation..

What format specifiers does scanf and printf use to specify a double type in a string literal?
The format specifier that scanf and printf use to specify a double type in a string literal is %lf.

What are integer variables typically used for?
Integer variables are typically used for values that are counted.

What are floating-point variables typically used for?
Floating-point variables are typically used for measurements or fractions of countable items.

What does dividing a positive floating-point value by 0.0 result in?
Dividing a positive floating-point value by 0.0 results in positive infinity.

What does dividing 0.0 by 0.0 result in?
Dividing 0.0 by 0.0 results in Not a Number (NaN).

What does NaN stand for?
NaN stands for Not a Number.

What format specifier do you use to print the first two digits after the decimal point in a double?
The format specifier that you use to print the first two digits after the decimal point in a double is %.2lf.

Does the fractional part of a floating-point number round itself if you use a format specifier?
Yes, the fractional part of a floating-point number rounds itself if you use a format specifier.

Scientific notation for floating-point literals

What are three steps of writing a number in scientific notation in C?
The three steps of writing a number in scientific notation in C are:

  1. Write the first non-zero digits as a floating point number.
  2. Write e.
  3. Write the exponent for the power of ten.

What does the exponent of the power of ten do to the decimal point in a number written in scientific notation?
In a number written in scientific notation, the exponent of the power of ten shifts the decimal point to the left or right by that amount.

In what direction does a negative exponent in scientific notation shift the decimal point?
A negative exponent in scientific notation shifts the decimal point to the left.

In what direction does a positive exponent in scientific notation shift the decimal point?
A positive exponent in scientific notation shifts the decimal point to the right.

How would you write Avogadro's number in scientific notation in C?
To write Avogadro's number in scientific notation in C, you would write 6.02e23.

3.9 Constant variables

What is considered good practice when it comes to literal numbers?
Good practice when it comes to literal numbers is to minimize the use of them.

What is an alternative to using literal numbers?
An alternative to using literal numbers is defining constants.

What is a constant variable?
A constant variable is an initialized variable whose value cannot be changed.

What is considered good practice for naming constant variables?
Good practice for naming constant variables is using uppercase letters and words separated by underscores.

3.10 Using math functions

What function do you use to get the absolute value of a floating-point number?
The function you use to get the absolute value of a floating-point number is fabs().
...

3.11 Integer division and modulo

What division is performed when the operands of / are integers?
The division performed when the operands of / are integers is integer division.

What division is performed when one of the operands of / is a floating-point number?
The division performed when one of the operands of / is a floating-point number is floating-point division.

The second operand of / or % must never be ...
The second operand of / or % must never be 0.

What error do you get if you perform division or modulus by 0?
If you perform division or modulus by 0, you get a divide-by-zero error.

What type of error is a divide-by-zero error?
A divide-by-zero error is a runtime error.

What is a runtime error?
A runtime error is a severe error which occurs while the program is running and causes it to terminate early.

What does the modulo operator do?
The modulo operator evaluates the remainder of the division of two numbers.

...

3.12 Type conversions

What is a type conversion?
A type conversion is a conversion of one data type to another.

What is implicit conversion?
Implicit conversion is when the compiler automatically converts between data types to avoid loss of data.

What will the compiler do if one operand is an integer and the other is a double?
If one operand is an integer and the other is a double, the compiler will promote the integer to a floating-point number.