File 1149 UNIT2
File 1149 UNIT2
Operator
An operator is a symbol that operates on a value or a variable. For example: + is
an operator to perform addition.
C has a wide range of operators to perform various operations.
C Arithmetic Operators
* multiplication
/ Division
#include <stdio.h>
int main()
{
int a = 9,b = 4, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c = a/b;
printf("a/b = %d \n",c);
c = a%b;
printf("Remainder when a divided by b = %d \n",c);
return 0;
}
Arithmetic Operators
Relational Operators
Logical Operators
Bitwise Operators
Assignment Operators
Arithmetic Operators
The following table shows all the arithmetic operators supported by the C
language.
Relational Operators
The following table shows all the relational operators supported by C. Assume
variable A holds 10 and variable B holds 20 then −
Show Examples
> Checks if the value of left operand is greater than the (A > B)
value of right operand. If yes, then the condition is not
becomes true. true.
< Checks if the value of left operand is less than the (A < B)
value of right operand. If yes, then the condition is true.
becomes true.
Bitwise Operators
Bitwise operator works on bits and perform bit-by-bit operation. The truth
tables for &, |, and ^ is as follows −
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1
Operator Description Example
& Binary AND Operator copies a bit to the result (A & B) = 12,
if it exists in both operands. i.e., 0000 1100
Assignment Operators
The following table lists the assignment operators supported by the C language
−
Examples
Comments
Comments provide clarity to the C source code allowing others to better
understand what the code was intended to accomplish and greatly helping in
debugging the code. Comments are especially important in large projects
containing hundreds or thousands of lines of source code or in projects in which
many contributors are working on the source code.
A comment starts with a slash asterisk /* and ends with a asterisk slash */ and
can be anywhere in your program. Comments can span several lines within your
C program. Comments are typically added directly above the related C source
code.
// C program to demo
// Single Line comment
#include <stdio.h>
int main(void)
{