practice exam b

practice exam b - KEY CPSC 206 507 EXAM B Spring 2006...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
KEY CPSC 206 – 507 EXAM B Spring 2006 SID/SSN: Score Possible Points Part One 30 pts Part Two 40 pts Part Three 20 pts Part Four 20 pts Total 110 pts 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
PART ONE (30 points) 1. What is the output of the following code? #include <stdio.h> int f(int a) { return (a + a); } int g(int *x) { return (*x + *x++); } int main(void) { int i = 5, j = 6; printf(" f = %d\n", f(i + j)); printf(" g = %d\n", g(&i)); i = i + 2; printf(" g = %d\n", g(&i)); printf(" g = %d\n", g(&j)); printf(" i = %d j = %d\n", i, j); return 0; } Answer: f = 22 ((5+6)+(5+6)) g = 10 ((i)+(i++))=(5+5) g = 14 ((i+2)+(i+2)++)=(7+7) g = 12 ((j)+(j++))=(6+6) i = 7 j = 6 2
Background image of page 2
2. What is the output of the following code? #include <stdio.h> int go_on (int x) { return (x++ < 5); } int tap(int y) { int i; for ( i = y; i--;) printf ("tap "); printf ("\n"); } int main(void) { int x, i = 0; Note: gnw changed to int x = 2, i = 0; while (go_on(x)) tap (++x); return 0; } Answer: tap tap tap tap tap tap tap tap tap tap tap tap 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3. What is the output of the following code? #include <stdio.h> void swap (int *m, int *n) { int temp = *m; *m = *n; *n = temp; } int main (void) { int a[4] = {2,7,4,8}; int i, j; for (i = 3; i > 0; --i) { for (j = 0; j < i; ++j) if (a[j] < a[j+1]) swap (&a[j], &a[j+1]); for (j = 0; j < 4; ++j) printf ("%d ",a[j]); printf ("\n"); } return 0; } Answer: 7 4 8 2 7 8 4 2 8 7 4 2 4
Background image of page 4
PART TWO (40 points). Each question is worth 5 points. Short Answers.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/19/2012 for the course MATH MATH 304 taught by Professor Young during the Spring '09 term at Texas A&M.

Page1 / 8

practice exam b - KEY CPSC 206 507 EXAM B Spring 2006...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online