Quiz, Lecture 5


Identify the syntactical, logical, and stylistic errors in the following program:


/************************************************
program : Night Rider
author  : M. Night
*************************************************

#include < stdio.h >

#define MAX_SPEED = 65;
#define MIN_SPEED 40

int main (void){
  int a, b, truckMin, truckMax;
  double t_avg;

  /* Assigns MIN_SPEED to variable a */
  a == MIN_SPEED;
  b == MAX_SPEED;
  truckMin = MIN_SPEED - 10;
  truckMax = MAX_SPEED - 10;

  /* t_avg gets the average truck speed*/
  t = truckMin + truckMax / 2;

  /* let people go a bit faster */
  MAX_SPEED = MAX_SPEED + 10;
}


What are the values of x, y, and z after the execution of the following code fragment?


int x = 20;
int y = 42;
int z = 142;

if (x == y) x = x + 2;
if (y <= z) x = x + 2;
if ((x > 20) && (z != x)){
  y = z;
  z = x + 2;
}