Home > database >  What are comparative operators in C?
What are comparative operators in C?

Time:12-03

On my midterm there was a question that I believe has two correct answers, A and B. The question states:

Which of the following sets of operators is composed only of comparative operators?
A) >, <, >=, <=
B) ==, !=
C) &&, ||, !
D) None of the above.

Page 235 of my textbook (Computer Science: A Structured Programming Approach Using C by Forouzan and Gilberg) states,

C provides six comparative operators. … The operators are shown in Figure 5-4.

Figure 5-4 shows the operators <, <=, >, >=, ==, and !=. I emailed this to my lecturer and she responded with:

I understand the point you made in your submitted paper, but the best course of action is to stick to CS159 notes packet rather than Forouzan's textbook, as the textbook is considered a supplemental resource for this course.

Page 119 of my notes packet (Purdue University's CS159 notes packet) says that comparative operators are == and !=. So does comparative operator have two definitions? Even in that case the question would have two correct answers.

CodePudding user response:

§6.5.8 of the ISO C11 standard defines the operators <, >, <= and >= to be the "relational operators".

§6.5.9 of the ISO C11 standard defines the operators == and != to be the "equality operators".

The ISO C standard does not use the terms "comparative operators" or "comparison operators", so it also does not provide a definition for them.

However, all six of the operators mentioned above are intended for comparing both operands, so the most meaningful definition of such a term would include all of these operators.

CodePudding user response:

C defines

4 Relational operators: <, >, <=, >=

and

2 Equality operators: ==, !=.

C does not define comparative operator.

So unless you have some other source defining comparative operator, there is no definitive answer.


@Tom Karzes makes a good point: "... your course is adopting nonstandard terminology, then testing you on your understanding of that terminology. I would stick to the standard."

  • Related