Solution for Exercise 9-18
ex0918
#include <stdio.h> int main() { int x; for(x=0;x=10;x=x+1) { puts("What are you lookin' at?"); } return(0); }
Notes
* The "parentheses" compiler warning is the same one you see when using a single =
in an if
comparison. I'm not sure of the specifics, but the cause it the same: You used one equal sign (assignment) when you really want two (comparison).
* By the way, the value of variable x
cannot explode and stop the program, despite the action x=x+1
taking place after each iteration of the loop. The value of x
just keeps increasing until it reaches the maximum size for a signed int. At that point, the value rolls over to a negative number and continues to increment. If left unattended, the code above generates a program that never stops.
Copyright © 1997-2024 by QPBC.
All rights reserved