{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

In c there are six types of relational operators

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: l Operators The Relational operators are used to compare two values of the same type. In C++, there are six types of relational operators. Relational operator == != < > <= >= Definition Equal to Not equal to Less than Greater than Less than or equal to Greater than or equal to 14 Condition The expression contains the relational operator is called condition and it gives the result either true ( 1 ) or false ( 0 ). Examples Condition Result 3>4 false 4<5 true 10= =3 false 5!=4 true 4<=7 true 6>=6 true 15 15 Increment Operator (++) We often need to add 1 to the value of a variable. We can do this in the “normal” way as “normal” Count = Count + 1 ; Or we can use an arithmetic assignment operator: Count += 1; But there is an even more condensed approach: + + count ; The ++ operator increments (adds 1 to) its operand. ++ is increment ++ operator. operator. 16 16 Decrement operator (--) The decrement operator(- -) behaves very much like the increment operator, The except it subtracts 1 from it’s operand. It is used as follows it - - variable; Prefix and Postfix Notations The increment and decrement operators can be used in two ways: increment decrement As a prefix, meaning that the operator precedes the variable; and as a prefix meaning as postfix, meaning that the operator follows the variable. What’s the postfix meaning follows difference? Often a variable is incremented but how, it can be explained with the help of the following examples: explained 17 Prefix and Postfix Notations main(void) { int num = 0; printf(“\n Number = %d”, num); printf(“\n Number = %d”, ++ num); printf(“\n Number = %d”, num); } OUT PUT 0 1 1 main(void) { int num = 0; printf(“\n Number = %d”, num); printf(“\n Number = %d”, num ++); printf(“\n Number = %d”, num); } OUT PUT 0 0 1 18 18...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online