An error which almost every C programmer has made is shown below:
main() { int left=10; if ( left = 5 ) { puts(" Values are equal..."); } }
The program assigns 5 to the variable left and returns 5. This is interpreted as TRUE and causes the puts statement to be executed everytime.
Here is the corrected program.
main() { int left=10; if ( left == 5 ) /* Double equals required. */ { puts(" Values are equal..."); } }
Top | Master Index | Keywords | Functions |