BASIC C EXERCISES READING ------- Notes for lecture 2. Kernighan and Ritchie, 2.10, 2.11, 3.1-3.7 SUPPLEMENTAL READING -------------------- Deitel and Deitel, Chapters 3 and 4 EXERCISES --------- 1. What do the following C statements do? t = x; x = y; y = t; 2. Is the following a legal C program? #include main { int c; c = 5; printf("%d \n", c); } 3. What is wrong with the following C statements? A. if (a > b) then c = 0; B. if a > b { c = 0; } C. if (a > b) c = 0; D. if (a > b) c = 0 else b = 0; 4. What is the value of j after the following code is executed? for (i = 0, j = 0; i < 10; i++) j += i; 5. What is the value of j after the following code is executed? for (i = 0, j = 1; i <= 10; i++) j += j; 6. What is the value of i after the following code is executed? for (i = 0; i < 10; i++) i += i; . . ANSWERS TO BASIC C EXERCISES 1. Exchanges x and y. 2. Not legal. Parentheses () needed after "main". 3. A. No keyword "then" in C. B. Always need parentheses around the conditional. C. Nothing wrong. This one is OK. D. Missing semicolon before "else". 4. 45 5. 2048 6. 15