Function comparison

Probably a very easy question but why the first function works (gives correct output) meanwhile the second does not?

1
2
3
4
5
6
char complement(char c) {
	if (c == 'A') return 'T';
	if (c == 'T') return 'A';
	if (c == 'C') return 'G';
	if (c == 'G') return 'C';
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
char complement(char c) {
	if (c == 'A') {
		c == 'T';
		return c;
	}
	if (c == 'T') {
		c == 'A';
		return c;
	}
	if (c == 'C') {
		c == 'G';
		return c;
	}
	if (c == 'G') {
		c == 'C';
		return c;
	}
}
Last edited on
You are using double equal signs before returning when setting c in the second example. It should be c='G' not c=='G'.
== does not modify the value but rather compares two values to see if they are equal (thus why its used in if statements). = alone sets it.
Last edited on
Thanks
Topic archived. No new replies allowed.