When do you use "if ( a = b )"? (was Re: Funny mistake)
Sven Heinicke
sven at cs.widener.edu
Mon Mar 18 02:11:37 AEST 1991
In <65837 at eerie.acsu.Buffalo.EDU>, chu at acsu.buffalo.edu writes:
>In article <775 at camco.Celestial.COM> bill at camco.Celestial.COM (Bill Campbell) writes:
>[concerning "if ( a = b )"
>
>It's been my mistake everytime I've done it!! I realize that it is a
>legal construction and I know what it does, but I was wondering...
>Is there a good use for this?
>
I went through some of the programs that I wrote and here is probely
the best example of a good use for it that was kind of easy to
understand (if finds the greatest common demonator of a and b). You
can write the program without in in the while statment but it was the
easest place I could find to put it.
int gcd(a,b)
int a,b;
{
int r,q;
while(r = a%b)
{
q = a/b;
a = b;
b = r;
}
return(b);
}
--
sven at cs.widener.edu Widener CS system manager
Sven Mike Heinicke and Student
(pssmheinicke at cyber.widener.edu (if you must))
More information about the Comp.lang.c
mailing list