CSE 142 Quiz 2
June 29, 2000
Name:
SID:
Answer the following questions:
1) What is the value and type of the following expression:
1 + (int)(10.0 + 3 * ((13 % 4) + (4/3) + 2 * 0.5))
value 20, type integer (int) 2) Circle the errors in the following piece of code:
(Both syntax and semantic errors)
#include <stdio.h>; /* misplaced semicolon */ #define CM_PER_INCH 2.54 int main(void) { int inches; double centimeters; /* semicolon was missing */ printf("Enter the number of inches: ",inches); /* ,inches shouldn't be there */ scanf("%d",&inches); /* missing & */ centimeters = inches + CM_PER_INCH; /* semantic -- should be * */ printf("%d inches equals %f centimeters\n", inches, centimeters); return 0; }
3) What is printed by the following code:
int x = 7; int y = 0; if (x > 10.0) printf("142 is boring!\n"); if (x < 10.0) { y = 142; printf("%d is great!\n", y); } printf("This is fun!\n"); 142 is great! This is fun!