Operators in C Programming

December 15, 2011

Run C Program Online

In C programming language, one can find various operators for performing different kind of operations. There are operators for arithmetic functions, assignment, logical functions, and others.

Operators in C language work on constants and variables, though few are restricted for certain works. Most of the operators are binary; few operators are unary and that takes only one operand.

Arithmetic Operators

Arithmetic operators are used for addition (+), multiplication (*), subtraction (-), and division operations. In addition to these arithmetic operators, there is a modulus operator to give the remainder from the division operator.

Sample Code

1. #include
2.
3. Void main()
4. {
5. int x = 200;
6. int y = 4;
7. int z;
8.
9. z = x + y;
10. printf( “x + y = %dn”, z );
11.
12. c = a – b;
13. printf( “x – y = %dn”, z );
14.
15.
16. printf( “x * y = %dn”, x* y );
17.
18. c = a / b;
19. printf( “x / y = %dn”, z );
20.
21. c = 100 % 3;
22. printf( “x % y = %dn”, z );
23. }

Though the common definition of main() function is nothing but int main(), not many compilers allow main() function to return void. The standard C allows for implementation of defined versions that doesn’t return int.

The output of the above program is:

x + y = 103
x – y = 97
x * y = 300
x / y = 33
x % y = 1

Subscribe

Subscribe to our e-mail newsletter to receive updates.

No comments yet.

Leave a Reply