Mathematics 1201: Programming in C Model Solutions to Midterm Test 2 Prof. Wickerhauser In Problems 1--6 below, find the value of `x' after all of the following statements are executed: Problem 1. #define HUH(x,y) ((x)>(y)?#x:#y) x = HUH(5,-7); ANSWER 1: "5" Problem 2. int i[]={4,3,2,1,0,-1}, *ptr, x=1; ptr = i; while ( *ptr ) x *= *ptr++; ANSWER 2: 24 Problem 3. float x, array[99] = {-12}; x = array[12]; ANSWER 3: 0.000000 Problem 4. int x, a[10]; x = &a[2] - a; ANSWER 4: 2 Problem 5. #include int x = 'e', y = '\t'; x = isspace(y) ? toupper(x) : 0; ANSWER 5: 'E' Problem 6. typedef struct Link { int Value; struct Link *Next; } *Link; int i; Link Old=0, New; for(i=0; i<100; i++) { New = (Link)malloc(sizeof(struct Link)); New->Next = Old; New->Value = i; Old = New; } for(i=0; i<5; i++) New = New->Next; x = New->Value; ANSWER 6: 94 Problem 7. Write a complete ANSI C program that reads characters from the standard input until it reaches the end-of-file marker, then returns the number of semicolons read. Be sure to include all the needed standard header files. ANSWER: #include main(void) { int count=0, Ch; while ( (Ch=getchar()) != EOF ) if( Ch==';' ) ++count; puts("Midterm Test, Problem 7: "); printf("%d semicolons in the file.\n", count); }