Showing posts with label opreators. Show all posts
Showing posts with label opreators. Show all posts

Friday, 2 November 2012

Program Of And, comma(,) , Relational(>) Operator In C++


#include<iostream.h>
#include<conio.h>

{

clrscr();

int a,b,c;

cout<<"Enter a,b,c";

cin>>a>>b>>c;


{
cout<<"\n a is Greater";

}


{
cout<<"\n b is Greater";

}


{
cout<<"\n c is Greater";

}


getch();
}

Sunday, 29 April 2012

Program Of Unary Operators In C++


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c,d,e,f,g,h;
a=10;
b=++a;    //b=11 , a=11
c=--a;   //c=10 , a=10
d=a--;   //d=10, a=9
e=a++;   //e=9,a=10
f=a++;  //f=10 , a=11
g=++a;  //g=12, a=12
h=a--;  //h=12, a=11
cout<<"\n a="<<a;
cout<<"\n b="<<b;
cout<<"\n c="<<c;
cout<<"\n d="<<d;
cout<<"\n e="<<e;
cout<<"\n f="<<f;
cout<<"\n g="<<g;
cout<<"\n h="<<h;
getch();
}
-----------------------------------------------
Define Unary Operator

Unary operators operate on one operand(variable or constant). There are two types of unary operators- increment and decrement.

Program Of Shift Operators In C++

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c;
a=10;
b=a>>3;          // >> Shift Left
c=a<<3;           // << Shift Right
cout<<" a>>3="<< b;
cout<<"\n  a<<3="<< c;

getch();
}

Saturday, 28 April 2012

Program Of Conditional Operators In C++

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a,b,c;
cout<<"Enter First Number";
cin>>a;
cout<<"Enter Second Number";
cin>>b;
cout<<"Greater Number="<<c;  // ?: Conditional Operator
getch();
}
------------------------------------------
 Define Conditional Operator

The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows:

1.
     The first operand is implicitly converted to bool.     It is evaluated and all side effects are completed before continuing.
  • 2.   If the first operand evaluates to true (1), the second operand is evaluated.

  • 3.   If the first operand evaluates to false (0), the third operand is evaluated.

The result of the conditional operator is the result of whichever operand is evaluated — the second or the third. Only one of the last two operands is evaluated in a conditional expression.
Conditional expressions have right-to-left associativity. The first operand must be of integral or pointer type. The following rules apply to the second and third expressions: 

  • If both expressions are of the same type, the result is of that type.

  • If both expressions are of arithmetic or enumeration types, the usual arithmetic conversions (covered in Arithmetic Conversions) are performed to convert them to a common type.

  • If both expressions are of pointer types or if one is a pointer type and the other is a constant expression that evaluates to 0, pointer conversions are performed to convert them to a common type.

  • If both expressions are of reference types, reference conversions are performed to convert them to a common type.

  • If both expressions are of type void, the common type is type void.

  • If both expressions are of a given class type, the common type is that class type.
Any combinations of second and third operands not in the preceding list are illegal. The type of the result is the common type, and it is an l-value if both the second and third operands are of the same type and both are l-values.

Program Of Compare Operators In C++

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int marks;
cout<<"Enter Marks=";
cin>>marks;
if(marks>=40)     // >= ,==,<= ,etc Comapare Operator
{
cout<<"Pass";
}
else
{
cout<<"Fail";
}
getch();
}
--------------------------------
  Define Compare Operator

There are 6 relational or compare operators:
OperatorSymbolFormOperation
Greater than>x > ytrue if x is greater than y, false otherwise
Less than<x < ytrue if x is less than y, false otherwise
Greater than or equals>=x >= ytrue if x is greater than or equal to y, false otherwise
Less than or equals<=x <= ytrue if x is less than or equal to y, false otherwise
Equality==x == ytrue if x equals y, false otherwise
Inequality!=x != ytrue if x does not equal y, false otherwise
You have already seen how all of these work, and they are pretty intuitive. Each of these operators evaluates to the boolean value true (1), or false (0).
Keep in mind that comparing floating point values using any of these operators is dangerous. This is because small rounding errors in the floating point operands may cause an unexpected result. See the section on floating point numbers for more details.
However, sometimes the need to do floating point comparisons is unavoidable. In this case, the less than and greater than operators (>, >=, <, and <=) are typically used with floating point values as normal. The operators will produce the correct result most of the time, only potentially failing when the two operands are almost identical. Due to the way these operators tends to be used, a wrong result typically only has slight consequences.


Sunday, 29 January 2012

Program Of Conditional Operators In C


#include<stdio.h>
#include<conio.h>
 main()
{
int a;
clrscr();
a=56;        // = ----> assignment Operator
if(a>=40)  // >= ---> Conditional Operator
{
printf("\n Pass");
}
else
{
}
getch();
}

--------------------------------------------------------------

The conditional operator (? :) is a ternary operator (it takes three operands). The conditional operator works as follows:
The first operand is implicitly converted to bool. It is evaluated and all side effects are completed before continuing.
If the first operand evaluates to true (1), the second operand is evaluated.
If the first operand evaluates to false (0), the third operand is evaluated.

The result of the conditional operator is the result of whichever operand is evaluated — the second or the third. Only one of the last two operands is evaluated in a conditional expression.

Conditional expressions have right-to-left associativity. The first operand must be of integral or pointer type. The following rules apply to the second and third expressions:
If both expressions are of the same type, the result is of that type.
If both expressions are of arithmetic or enumeration types, the usual arithmetic conversions (covered in Arithmetic Conversions) are performed to convert them to a common type.
If both expressions are of pointer types or if one is a pointer type and the other is a constant expression that evaluates to 0, pointer conversions are performed to convert them to a common type.
If both expressions are of reference types, reference conversions are performed to convert them to a common type.
If both expressions are of type void, the common type is type void.
If both expressions are of a given class type, the common type is that class type.

Any combinations of second and third operands not in the preceding list are illegal. The type of the result is the common type, and it is an l-value if both the second and third operands are of the same type and both are l-values.


view source:--http://msdn.microsoft.com/en-us/library/e4213hs1(v=vs.71).aspx