Professional Documents
Culture Documents
* multiplication
/ division
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;
}
C PROGRAMMING OPERATORS
return 0;
}
C PROGRAMMING OPERATORS
Assignment Operators
Operator Example Same as
= a=b a=b
+= a += b a = a+b
-= a -= b a = a-b
*= a *= b a = a*b
/= a /= b a = a/b
%= a %= b a = a%b
C PROGRAMMING OPERATORS
Example : Assignment Operators
#include <stdio.h> c *= a; // c is 25
int main() printf("c = %d\n", c);
{ c /= a; // c is 5
int a = 5, c; printf("c = %d\n", c);
c %= a; // c = 0
c = a; // c is 5 printf("c = %d\n", c);
printf("c = %d\n", c);
c += a; // c is 10 return 0;
printf("c = %d\n", c); }
c -= a; // c is 5
printf("c = %d\n", c);
C PROGRAMMING OPERATORS
Relational Operators
Meaning of
Operator Operator Example
== Equal to 5 == 3 is evaluated to 0
If c = 5 and d = 2 then,
&& Logical AND. True only if expression ((c==5) &&
all operands are true
(d>5)) equals to 0.
If c = 5 then,
Logical NOT. True only if
! the operand is 0 expression !(c==5)
equals to 0.
C PROGRAMMING OPERATORS
#include <stdio.h>
int main()
{
int a;
float b;
double c;
char d;
printf("Size of int=%lu bytes\n",sizeof(a));
printf("Size of float=%lu bytes\n",sizeof(b));
printf("Size of double=%lu bytes\
n",sizeof(c));
printf("Size of char=%lu byte\n",sizeof(d));
return 0;
}
Conditional Statement
Conditional Statement
• Conditional Statements Are Used To Execute A
Set Of Statements On Some Conditions.
• It Provides A Unit Of Block In Which We Can
Either One Statement Or More Than One
Statements.
• If The Given Condition Is True Then The Set Of
Statements Are Executed Otherwise Body Is
Skipped.
if…else syntax
• if … else statement is used to express decisions.
Formally the syntax is :
if (expression)
statement1
else
statement2
• The expression inside if … else statement expects a
value. If the value is nonzero then it is true. If the
value is 0 then it is false.
if…else syntax
• Example:
void main()
{
int x ,y=0, a=2, b=3 ;
if(y>0)
x = a;
else
x = b;
printf(“%d“,x);
}
Thanks for your time and attention.