Operators in C
Operators in C
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
clrscr();
printf("\nEnter two float values:\n");
scanf("%f%f",&a,&b);
c=a+b;
printf("\nThe Sum of %0.2f and %0.2f is : %0.2f",a,b,c);
getch();
}
Operators in C:
Arithmetic = - * / %
Relational
Assignment
Bitwise
Logical
Increment / Decrement
Ternary
Assignment Operator:
= += -= *= /=
- Assigning the value to the variable
- Assigns the values from the Right side to the left side
- Assignment Operator =
- To the left of assignment operator is variable
- To the right of the assignment operator is value
- Only one index value can be assigned at a time
Ex:
c=a+b;
b is added with a and then assigns to c
int a=10,b=20;
a+=b;
a=a+b;
a=10+20;
a=30;
a=30,b=20
//Assignment Operator =
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter the Value for a : ");
scanf("%d",&a);
printf("\nEnter the Value for b : ");
scanf("%d",&b);
printf("\nBefore Using Assignemt Operator:");
printf("\na = %d @ %x",a,&a);
printf("\nb = %d @ %x",b,&b);
a=b; //Assigning the value of b to a
printf("\nAfter Using Assignemt Operator:");
printf("\na = %d @ %x",a,&a);
printf("\nb = %d @ %x",b,&b);
getch();
}
//Assignment Operator +=
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter the Value for a : ");
scanf("%d",&a);
printf("\nEnter the Value for b : ");
scanf("%d",&b);
printf("\nBefore Using Assignemt Operator:");
printf("\na = %d @ %x",a,&a);
printf("\nb = %d @ %x",b,&b);
a+=b; //a=a+b
printf("\nAfter Using Assignemt Operator:");
printf("\na = %d @ %x",a,&a);
printf("\nb = %d @ %x",b,&b);
getch();
}