Lesson 02 - Operators in C
Lesson 02 - Operators in C
Arithmetic operators
Relational operators
Logical operators
Bitwise operators
Assignment operators
Conditional operators
Special operators
C supports all
the basic
arithmetic
operators.
The following
table shows
all the basic
arithmetic
operators.
#include <stdio.h>
int main()
{
int a = 5, b = 20, c ;
if ( a && b ) { printf("Line 1 - Condition is true\n" );}
if ( a || b ) { printf("Line 2 - Condition is true\n" );}
/* lets change the value of a and b */
a = 0; b = 10;
if ( a && b ) { printf("Line 3 - Condition is true\n" );}
else { printf("Line 3 - Condition is not true\n" );}
if ( !(a && b) ) { printf("Line 4 - Condition is true\n" );}
return 0;
}
Assume A = 60
and B = 13 in
binary format,
they will be as
follows −
A = 0011 1100
B = 0000 1101
sizeof operator: sizeof is a much used in the C/C++ programming language. It is a compile
time unary operator which can be used to compute the size of its operand. The result of
sizeof is of unsigned integral type which is usually denoted by size_t. Basically, sizeof
operator is used to compute the size of the variable. To learn about sizeof operator in details
you may visit this link.
Comma Operator: The comma operator (represented by the token ,) is a binary operator
that evaluates its first operand and discards the result, it then evaluates the second operand
and returns this value (and type). The comma operator has the lowest precedence of any C
operator. Comma acts as both operator and separator. To learn about comma in details visit
this link.
#include <iostream>
using namespace std;
int main()
{
int test = 0; s
cout << "First character " << '1' << endl;
cout << "Second character " << (test ? 3 : '1')
<< endl;
return 0;
}