A) Relational operator

Relational operators are used to compare the value of two expression depending on their relations.
An expression that contain relational operator is called relational expression.
If the relation is true then the value of relational expression is 1 if the relation is false then the value of expression is zero.

The relational operators are

 Operators Meanings < <= == != > >= Less than Less than or equal to Equal to Not equal to Greater than Greater than or equal to

Let us take two variable equal to 9 be equal to 5 and from simple relation expression with them.

 Expression Relation Value of expression ab a>=b a==0 b!=0 a>8 2>4 False False False True True True False True True False 0 0 0 1 1 1 0 1 1 0

The relational operators are generally used in if else construct and loop

Example:/* program to understand the use of relational operator*/

# include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the values for a and b:\n");
scanf("%d%d", &a, &b);
if(a<b)
printf("%d is less than %d\n",a,b);
if(a<=b)
printf("%d is less than or equal to %d\n",a,b);
if(a==b)
printf("%d is equal to %d\n",a,b);
if(a!=b)
printf("%d is not equal to %d",a,b);
if(a>b)
printf('%d is greater is than %d\n",a,b);
if(a>=b)
printf("%d is greater than or equal to %d\n",a,b);
getch();
}
Output:
Enter the value of a and b: 12    7
12 is not  equal to 7.
12 is greater than 7.
12 is greater than or equal to 7.
It is important to note that the assignment operator(=) and equality operator(==) are entirely different.
Assignment operator is used for assigning the value while equality operator is used for comparison.
B) Bitwise operator

It has the ability to support the manipulation of data at the boolean level.
Bitwise operators are used for operation on individual bits.
Bitwise operation operate on integer only. int char or long int.
The Bitwise Operators are:-

 Operators Meanings & | ^ ~ << >> Bitwise AND Bitwise OR Bitwise XOR Bitwise complement Left shift Right shift

Before the execution of program: the number entered through the keyboard is 8 and its corresponding binary number is 1000.

 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 15      14      13      12      11      10      09      08      07      06      05      04     03     02      01  00

After the execution of program.

 0       0       0      0       0        0        0         0        0         0        0       0        1        0        0       0 15    14     13     12    11      10      09      08       07       06       05    04      03      02       01    00

Shifting to be tried means the input number is to be divided by 2 to the power s(2^s) where s the number of Shifts.
Y=n/2^s.
Where n equal to number, s equal to number of position to be shifted.
As per program Y=8/ 2^2=8/4=2.

example/* program to shift input data by 2 bit to left*/
#include<studio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr()
printf("Read a and b from the keybord (a&b):-");
scanf("%d%d",&a,&b);
c=a&b;
printf("The answer after ANDing is(c)=%d", c);
getch();
}
Output: Read a and b from the keyboard (a&b):- 8 4
The answer after ANDing is(c)=0.

1 comment:

1. Basic Electronics Engineering (EC101)

Basic Electronics Engineering (EC101)