- + Adds two Operands
- - Used for subtraction
- * Used for multiplication
- / Used for Division
- % Used for Modulus
- ++ Increment Operator
- -- Decrement Operator
Let's see how we can implement these operations in C program Coding.
Here we are taking 2 inputs from the user and scanning the input values to the address of the "num1" and "num2" variable memory location, and doing the arithmetic operation.
Here the inputs for the 1st Number is 20 and the 2nd Number is 10.
#include<stdio.h>int main(){int num1,num2;printf("Enter 1st Number:");scanf("%d",&num1);printf("Enter 2nd Number:");scanf("%d",&num2);printf("Sum value is: %d \n",num1+num2);printf("Subtraction value is: %d \n",num1-num2);printf("Multiplication value is: %d \n",num1*num2);printf("Division value is: %d \n",num1/num2);printf("Modulus value is: %d \n",num1%num2);num1++;printf("num1++ value is: %d \n",num1);++num1;printf("++num1 value is: %d \n",num1);num2--;printf("num2-- value is: %d \n",num2);--num2;printf("--num2 value is: %d \n",num2);return 0;}
O/P
Enter 1st Number:20
Enter 2nd Number:10
Sum value is: 30
Subtraction value is: 10
Multiplication value is: 200
Division value is: 2
Modulus value is: 0
num1++ value is: 21
++num1 value is: 22
num2-- value is: 9
--num2 value is: 8
Q.What "++" operator does?
A. It increments the value with 1.
Example:- int x=2;
x++;
print("%d",x);
O/P:-3
It means x++ is same as x=x+1;
and aswell ++x means x=x+1;
Q. If x++ and ++x is same then why it is defined in two different way?
It is the same but in x++ condition, the statement executes 1st then assigns the incremented by 1 value later;
but in ++x 1st the increase will happen then the execution will happen.
It is the same for x-- and --x; It means x=x-1;
It will decrease the value by 1.
To see the difference change the coding by following
#include<stdio.h>
int main(){
int num1,num2;
printf("Enter 1st Number:");
scanf("%d",&num1);
printf("Enter 2nd Number:");
scanf("%d",&num2);
printf("num1++ value is: %d \n",num1++);
printf("++num1 value is: %d \n",++num1);
printf("num2-- value is: %d \n",num2--);
printf("--num2 value is: %d \n",--num2);
return 0;
}
Enter 1st Number:20
Enter 2nd Number:10
num1++ value is: 20
++num1 value is: 22
num2-- value is: 10
--num2 value is: 8
Hope this article helps you please give feedback in the comment section
Thank you.