Copyright © tutorialspoint.com

Latest C Tutorial

C - Arithmatic Operators Examples

previous

Try following example to understand all the arithmatic operators. Copy and paste following C program in test.c file and compile and run this program.

main()
{
   int a = 21;
   int b = 10;
   int c ;

   c = a + b;
   printf("Line 1 - Value of c is %d\n", c );
   c = a - b;
   printf("Line 2 - Value of c is %d\n", c );
   c = a * b;
   printf("Line 3 - Value of c is %d\n", c );
   c = a / b;
   printf("Line 4 - Value of c is %d\n", c );
   c = a % b;
   printf("Line 5 - Value of c is %d\n", c );
   c = a++; 
   printf("Line 6 - Value of c is %d\n", c );
   c = a--; 
   printf("Line 7 - Value of c is %d\n", c );

}

This will produce following result

Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 21
Line 7 - Value of c is 22

previous

Copyright © tutorialspoint.com