Operators for comparison – CSKC
Sign In

Search

Code Learning #CPP#1736    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

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

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



Share

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