Martha's CIS 52 Midterm ANSWERS!

Question #1 (13). What do you use to separate multiple arguments that are passed to a function?
  1. a period (.)
  2. a comma (,) p. 133
  3. a forward slash (/)
  4. a backwards slash (\)

Question #2 (14). The echo() and print() satements are functions. True or False? p. 132 - they're language constructs

Questions #3 (16). How many PHP script sections can you include within a document?

  1. 1
  2. 2
  3. 10
  4. There is no limit -p. 79

Question #4 (17). Which of the following versions of the print() statement can you use in script? (Choose all that apply)

  1. print "Welcome to Hawaii!";
  2. Print "Welcome to Hawaii!";
  3. PRINT "Welcome to Hawaii!";
  4. Print("Welcome to Hawaii!");

TEST:

Welcome to Hawaii!Welcome to Hawaii!Welcome to Hawaii!Welcome to Hawaii!

Question #5 (18). You create line comments in PHP code by adding _________________ to a line you want to use as a comment> (Choose all that apply.)

  1. ||
  2. **
  3. # - p. 81
  4. //

Question #6 (149-1). Which of the following is a valid variable name?

  1. SalesOrder
  2. salesOrder
  3. $SalesOrder - p. 88
  4. $1SalesOrder

Question #7 (149-2). You are not required to initialize a variable when you first declare it. True or False? p. 89; p. 132

Question #8 (149-3). Which is the correct syntax for declaring a variable and assignming it a string?

  1. $MyVariable = "Hello";
  2. $MyVariable = "Hello"
  3. "Hello" = $MyVariable;
  4. $MyVariable = Hello;

Question #9 (150-7). How many decimal places does an integer store?

  1. zero p. 90
  2. one
  3. two
  4. as many as necessary

Question #10 (150-8). Which of the following is NOT a floating-point number

  1. -139.35
  2. 3.17
  3. 10
  4. -7e11 (SEE: PHP.Net)

Question #11 (150-9). which of the following values can be assigned to a Boolean variable? (Choose all that apply.)

  1. true
  2. false
  3. 1
  4. yes

Answer: "when printing a Boolean in PHP, true is represented as 1, and false is represented as an empty string..." p. 93
p. 92 - Boolean has 1 of 2 special values: true or false;

Question #12 (151-14). What value is assigned to be the $ReturnValue variable in the statement:
$ReturnValue = 100 != 200;?

  1. true
  2. false
  3. 100
  4. 200

TEST (why does this work?):

1

Question #13 (151-15). Which arithmetic operators can be used as both prefix and postfix operators?

  1. ++ - p.100
  2. --
  3. =
  4. -

Question #14 (151-16). The And (&&) operator returns true if _____________.

  1. the left operand returns a value of true
  2. the right operand returns a vlaue of true
  3. the left operand and right operand both return a value of true - p. 103
  4. the let operand and right operand both return a value of false

Question #15 (151-17). What value is assigned to the $ReturnValue variable in the statement
$ReturnValue = !$x; assuming that $x has a value of true?

  1. true
  2. false
  3. null
  4. undefined

TEST (why is this so?):

1

Question #16 (151-19). The order of priority in which operations in an expression are evaluated is known as _____________.

  1. prerogative precedence
  2. operator precedence - p. 104
  3. expression evaluation
  4. priority evaluation

Question #17 (152-20). What is the value of the expression 4 * (2 + 3)?

  1. 11
  2. -11
  3. 20 - p. 105; parentheses overive operator precedence
  4. 14

Question #18 (196-4). A variable that is declared outside a function is called a(n) ___________.

  1. local
  2. class
  3. program
  4. global

Question #19 (196-5). A local variable must be declared ____________.

  1. before a function
  2. after a function
  3. within the braces of a function definition
  4. with the local keyword

Answer: p. 89 - assigned value of variable is present only within function of script where it resides

Question #20 (196-6).Which of the following autoglobals can you use to access submitted form values? - p. 89, superglobals

  1. $_GET
  2. $_POST
  3. $_SERVER
  4. $_REQUEST

Question #21 (196-7). which of the following is the correct syntax for an if statement?

  1. if (4MyVariable == 10);
    echo "Your variable is equal to 10.";
  2. if $MyVariable == 10
    echo "Your variable is equal to 10.";
  3. if ($MyVariable == 10)
    echo "Your variable is equal to 10.";
  4. if ($MyVariable == 10),
    echo "Your variable is equal to 10.";

TEST:

Your variable is equal to 10.

Question #22 (197-8). An if statement can include multiple statements provided that they _______________.

  1. execute after the if statement's closing semicolon
  2. are not contained within a command block
  3. do not include other if statements
  4. are contained within a command block

Question #23 (197-10). Whic is the correct syntax for an else clause?

  1. else (echo "Printed from an else clause.";
  2. else echo "Printed from an else clause.";
  3. else "echo 'Printed from an else clause.'";
  4. else; echo "Printed from an else clause.";

TEST:

Printed from an else clause.

Question #24 (197-11). The switch statement controls program flow by executing a specific set of statements, depending on _______.

  1. the result of an if...else statement
  2. the version of PHP being executed
  3. whether an if statement executes from within a function
  4. the value returned by a conditional expression

Question #25 (197-12). Decision-making structures cannot be nested. True or False?

Question #26 (197-13). When the value returned by a switch statement expression does not match case label, the statements with the _____________ label execute.

  1. exception
  2. else
  3. error
  4. default

Question #27 (197-14). You can exit a switch statement using a(n) ___________ statement.

  1. break - p.115
  2. end
  3. quit
  4. complete

Question #28 (198-15). Each repetition of a looping statement is called a(n) ______________.

  1. recurrence
  2. iteration - p.118
  3. duplication
  4. reexecution

Question #29 (198-16). which of the following is the correct syntax for a while statement?

  1. while ($i <= 5, ++$i) {
    echo "<p>$i</p>";
    }
  2. while ($i <= 5) {
    echo "<p>$i</p>";
    ++$i;
    }
  3. while ($i <= 5);
    echo "<p>$i</p>";
    ++$i;
    }
  4. while ($i <= 5; echo "<p>$i</p>") {
    ++$i;
    }

Question #30 (198-17). Counter variables _______________. (Choose all that apply.)

  1. can be incremented
  2. can be decremented
  3. can be changed using any conditional expression
  4. do not change.

Question #31 (198-19). Which of the following is the correct syntax for a for statement?

  1. for ($i = 0; $i < 10; ++i)
    echo "Printed from a for statement.";
  2. for ($i = 0, $i < 10, ++$i)
    echo "Printed from a for statement.");
  3. for {
    echo "Printed from a for statement.");
    } while ($i = 0; $i < 10; ++$i)
  4. for ($i = 0; $i < 10);
    echo "Printed from a for statement.");
    ++$i;

TEST: didn't work....

Question #32 (199-20). When is a for statement initialization expression executed?

  1. When the for statement begins executing
  2. with each repetition of the for statement
  3. when the counter variable increments
  4. when the for statement ends

Question #33 (199-21). The foreach statement can only be used with arrays. True or False?

**************************************************************

 

 

**************************************************************