Operators for comparison – Computer Sir Ki Class


Lost your password?

Don't have an account ?
Register (It's FREE) ×


Code Learning #CPP#1736 siteicon   siteicon   siteicon  

Operators for comparison

Using operators for equality, inequality, greater, lesser, greater or equal, lesser or equal types of comparisons.

Learning Objectives

  • Use of comparison operators like equal to, not equal to, greater than, less than, greater than equal to, less than equal to.

Source Code

TC++ #1736


Source Code

Run Output


Code Understanding

int a=10;
Here we declare integer variable a and assigning it to value 10.

if(a==10) cout<<a<<endl;
Since a is equal to 10 this line will produce print result. Notice the use of == (double equal to) sign. This is different from assignment sign which is a single = (equal to) sign.

if(a!=0) cout<<a<<endl;
Since a is a non zero value so a!=0 will produce true result and hence this line will also produce output.

if(a>0) cout<<a<<endl;
Since a is 10, which is greater than 0 so this line will also produce output.

if(a<100) cout<<a<<endl;
Since a is 10, which is less than 100 so this line will also produce output.

if(a >=10) cout<<a<<endl;
Since a is 10, which is less than or equal to 10 so this line will also produce output.

if(a <=10) cout<<a<<endl;
Since a is 10, which is greater than or equal to 10 so this line will also produce output.

Suggested Filename(s): operators-comp.cpp, comparisons.cpp


CSKC| Created: 15-Dec-2017 | Updated: 28-Aug-2018|

Introductory Sessions Beginning to Program Tokens Keyword and Identifiers Data Types Variables and Constants Operators Simple User Input Building Expressions and Formulas Simple Real World Problems Simple If and If Else Multiple-Nested-Ladder of If Else Switch case selection Simple Loops Tricks in Loops - break continue scope Loop Applications - Handling numerals Series printing loops Nested Loops Pattern printing loops Number Varieties and Crunches String Handling (Null Terminated) Strings - string class type Functions (Built-in) Functions - user defined Functions Reference Passing/Returning Arrays Concepts and 1-D Arrays Array Data Management Two dimensional arrays and Matrices Structures Basics Structures passing/returning 2D Array Memory Addressing Display Using IO Manipulation Display Using C Formatting Tricks User Defined Data Types Enumerated Types Preprocessor Directives And Macros Exception Handling Programming Paradigms and OOPs Advantages Abstraction and Encapsulation Polymorphism Inheritance Function Overloading Concepts Function Overloading Varieties Function Overloading Special Cases Defining Classes Creating and Using Class Objects Class Members Accessibility Class Function Types Inline Functions Constant Functions Nesting of Functions Class Members Scope Resolution Static Members in a Class Array of Objects Constructor Concepts Default Constructor Parameterized Constructor Copy Constructor Constructor Overloading Destructors Inheritance Fundamentals Public Derivations Private and Protected Derivations Multiple Inheritance Multi-Level Inheritance Class Nesting Data File Concepts Handling Text Files Handling Binary Files Pointer Concepts Pointer and Arrays Pointers and Functions Object Pointers This Pointer Linked Lists Stacks Queues