C++ Study Guide for Test 1

Card Set Information

C++ Study Guide for Test 1
2012-02-27 23:24:03
programming console output boolean statements functions variable scope pointers

C++ Study Guide for Test 1
Show Answers:

  1. What is pseudocode?
    Pseudocode is a mixture of C++ and ordinary English. It allows us to make our algorithm precise without worrying about the details of a C++ statement.
  2. What is an algorithm?
    An algorithm is a sequence of precise instructions which lead to a solution.
  3. What is the input and output(s) of the compiler?
    Input: source program or source code.

    Output: object program or object code.
  4. What are the 3 catagories of errors that can be made by a programmer?
    Syntax, run-time, and logic errors.
  5. What type of errors can a compiler detect?
    Sytax errors.
  6. How are run-time errors usually discovered?
    When the program is run.
  7. What errors must the programmer detect and correct during testing?
    Logic errors.
  8. What is meant by "echoing the input"?
    Input that appears on the screen as it is typed. A program should always write out the input values some time before it ends.
  9. What C++ commands are associated with each of the 4 control structures?
    Sequence Control, Selection Control (branching or If, If-Else), Repition Control, and Case Control (switch).
  10. How are comments symbols // and /* */ different?
    // covers only one line for comments.

    /* */ spans several lines for comments.
  11. What is the purpose of including comments in a program?
    To make the program more understandable and for explanatory notes at key places.
  12. What are some of the things a debugger allows a programmer to see?
    Mistakes, syntax errors, error and warning messages, and run-time errors.
  13. What are the different data types?
    Integer (int), floating-point types (double, long double, long float), characters (char).
  14. Why do we use meaningful naming conventions for variables?
    To make a program easy to understand.
  15. Are variable names case sensitive?
  16. What is variable initialization, and how can it be done in C++?
    Variable initialization is assigning a variable at the time that you declare the variable.

    It is done by adding an equal sign and a value.
  17. What are constant variables used for, and what is the preferred naming convention?
    Constant variables are used to mark a variable declaration so that the value of the variable cannot be changed.

    The preferred naming convention is to use const before the declaration.
  18. What special character is used to define an escape sequence?
  19. What do the escape sequences \n and \t do?
    \n is a new line.

    \t is a horizontal tab.
  20. What is endl used for?
    Its used to output a blank line.
  21. What does the "magic formula" for formatting output do?
    It causes numbers that contain a decimal point to be output in everyday notation with the exact number of digits after the decimal point that you specify.
  22. What are the precedence rules?
    They are rules that determine the order in which operators are performed.
  23. How do the parentheses affect the precedence rules?
    It makes the expression easier to read and less prone to programmer error.
  24. What can be lost from the result of integer division?
    Decimal number are lost during integer division.
  25. What does the modulus operator % return?
    It gives the remainder in division.
  26. What is the syntax to increment a variable by 1 using assignment statements, short hand notation, and incrementors?
    • n = n +
    • n += 1
    • n++
  27. What is the syntax to decrement a variable by 1 using assignment statements, short hand notation, and decrementors?
    • n = n -1
    • n -= 1
    • n--
  28. What would the following statement do to the variable num?
    num += -1;
    • num = num + num -1
    • or
    • no increment or decrement.
  29. What values are Boolean expressions evaluated to?
    True or False.
  30. What is the difference between the = and == symbols?
    = is part of an assignment statement.

    == is a Boolean expression "equal to".
  31. What is the difference between AND and OR operators?
    All expressions must be true in AND.

    Only 1 expression need be true in OR.
  32. What are the symbols for the AND and OR operators?
    AND is &&

    OR is ||
  33. What is the NOT operator and how does it effect the Boolean expression?
    ! is the operator symbol and it negates a Boolean expression.
  34. What is the difference between if and if-else statements?
    The if statement allows for 1 or 2 alternatives to do an action.

    The if-else statement chooses between 2 alternative actions.
  35. How does the compiler match an else with an if statement?
    The compiler always pairs an else with the nearest previous if that is not already paired with some else.
  36. Does the compiler take indenting you use into consideration to match else and if statements?
    The compiler does not care about indenting.
  37. What is the purpose of indenting if-else statements?
    It makes the program easier to read and shows the level of nested substatements.
  38. How can braces be used to prevent the dangling-else problem?
    Braces tell the compiler how to group things rather than leaving them to be grouped according to default conventions.
  39. What are the differences between the while and do-while loops?
    In a while statement, the Boolean expression is checked.

    In a do-while statement, the loop body is always executed at least once.
  40. What causes an infinite loop?
    A Boolean expression that is always true.
  41. What is involved in top-down design?
    Break down the task to be accomplished into subtasks, decompose subtasks into smaller subtasks and so forth.
  42. What is the purpose of structure charts?
    To show the overall structure of a program but omits specific logic. It is used for initial planning of a program.
  43. What is depicted in a structure chart?
    It shows what tasks need to be completed, not how they will be completed.
  44. Why is the black box analogy used to describe how functions should be written?
    It tells all the programmer needs to know if they put appropiate arguments into the black box and have an appropiate return value that will come out of the black box.
  45. Why are functions considered small programs?
    It uses formal parameters for input. Arguments to the function are the input and they are plugged in for the formal parameters. The function sends output back to the program using a return statement.
  46. What is the purpose of precondition and postconditions?
    Preconditions states what is assumed to be true when the function is called.

    Postconditions describe the effect of a function call which tells what will be true after the function is executed in which the precondition holds.
  47. Does the compiler require preconditions and postconditions?
    No, they are comments that describe the function declaration.
  48. What is the difference between formal parameters and arguments?
    A formal parameter is used as a blank or place holder to stand in for the argument.

    An argument is a constant or variable or complicated expression.
  49. When do we use formal parameters?
    When writing a function declaration which arguments are not known, formal parameters are used in place of arguments and they are used with function definitions.
  50. When do we use arguments?
    They are used with function calls.
  51. What is the purpose of the function declaration?
    The function declaration or prototype describes how the function is called. It tells you all you need to know to write a call to the function. It is required to appear in your code prior to a call to a function whose definition has not yet appeared and placed before the main part of the program.
  52. Why must the data types of parameters and arguments match?
    When an argument is plugged in for a formal parameter, the argument is plugged in for all instances of the formal parameter that occur in the function body.
  53. Why is it that the function declaration provides all of the information needed to write the function call?
    The function declaration tells you the name of the function, how many arguments the function needs, and what type the arguments should be.
  54. What is considered the function call?
    The expression on the right-hand side of the equal sign.
  55. What is included in the header of the a function definition?
    It describes how the function computes the value it returns. It acts like a small program and calling the function is the same thing as running this "small program".
  56. What is included in the body of a function definition?
    It consists of declarations and executable statements enclosed within a pair of braces.
  57. What does the return statement do in the function?
    It sends output or a value to the function.
  58. How many return statements can be in a body of a function?
  59. What is the main difference between void and other return types?
    The keyword void is used in place of the return type and second is the return statement does not contain an expression for the value to be returned since no value is returned.
  60. Why would you want a function that doesn't return a value?
    To output results of a calculation.
  61. What is the syntax for the return statement in void functions?
    • return;
    • which is optional before the closing brace of the function body.
  62. Can functions call functions that call other functions?
  63. What is passed to the function through a call-by-reference parameter?
    The addresses of the arguments are passed through the function's parameters instead of the values stored in the arguments.
  64. In a call-by-reference mechanism, how many values can be "returned" through the parameters?
    Many values can be returned.
  65. Can call-by-value and call-by-reference parameters be mixed?
  66. How are function names overloaded?
    Using the same function name but different parameter types or number of parameters.
  67. When function manes are overloaded, how are they uniquely identified?
    With their function signature.
  68. What is a function's signature consist of?
    Its function name and parameters.
  69. Where are global variables defined?
    They are defined before main and they can be referenced by all the functions in the program.
  70. Where are local variables for main defined?
    Within the main part of the program.
  71. Where are local variables for other functions defined?
    Within the body of a function definition.
  72. Are the variables listed in the function header declared as local variables of the function?
  73. When various functions declare variables of the same type with the same name, are they considered global variables?
    No, they are local to the function unless they are declared before main.
  74. How is a block of code defined?
    With an open and closed brace.
  75. Can local variables be declared in a block of code?
  76. What is a variable's scope?
    It determines in which function or block of code a particular variable exists in.
  77. What are pointer variables?
    They are a special type of variable that can store a memory address instead of a regular value.
  78. How is a pointer variable declared?
    Using an asterisk * as in int *pointerInt;
  79. What value does the & in front of a regular variable provide?
    The address assigned to the variable.