UMBC CS 201, Fall 98
UMBC CMSC 201 & 201H Fall '98 CSEE | 201 | 201 F'98 | lectures | news | help

== vs =

The Program

/* Program: equal.c. An example of a common, but bad bug. */ #include <stdio.h> main() { int n ; /* Set n to be FALSE */ n = 0 ; /* Error happens here. I meant to say if n is FALSE print "My program works", but instead I really set n to be FALSE again because I used = (the assignment operator) instead of == for comparison for equality. The expression (n = 0) evaluates to 0, so instead of the condition being TRUE, it is FALSE and the program prints "What's wrong??"*/ if ( n = 0 ) { printf("My program works!\n") ; } else { printf("What's wrong??\n") ; } }

The Sample Run

What's wrong??

The Lesson


CSEE | 201 | 201 F'98 | lectures | news | help

Saturday, 12-Sep-1998 16:51:32 EDT