MORE INFORMATION ON assign.c




The file assign.c is a sample source file that contains an intent error in the function "assign()". The intent error is that an assignment operator has been substituted for an equality test operator. Specifically, in the if statement, "(x=1)" has accidentally been coded instead of "if (x==1)".


The intent of the function is to test the value of a variable. If the variable is equal to 1, a nonzero is passed to the "if" function, which causes it to excute the "return 1" statement. This return of 1 to the main function causes the main function to print to the standard output device "1". If the variable is not equal to one, a zero is passed to the "if" function. This causes the excution of the "return 0" statement. The return of 0 causes the main function to display "0".


However, with the substitution of "(x=1)", the logic of the program differs. If 1 is assigned to "x" , a nonzero will be passed to "if", thus causing the execution of the "return 1" statement and the display of "1". Since "x" is declared of type "int", 1 can almost always be assigned to x, and thus the program will almost always display 1.




Click here for the source code.