1. Meet Our Group:
AZWAD HUSSAIN SHADMAN- 2023331504
JANNATUL FERDOUS MARIA- 2023331512
MOHAMMAD R RAFI CHOWDHURY- 2023331525
COMPUTER SCIENCE AND ENGINEERING
PRESENTATION
PRESENTING TO :
Md Lysuzzaman
Lecturer, Dept. Of CSE, SYLHET ENGINEERING
COLLEGE
2. Topics Overview :
We Will discuss about 3 Operators in C
Language :
Topics Overview :
1.Assignment Operator
2.Increment & Decrement Operator
3. Conditional Operator
3. Assignment Operator :
The assignment operator (=) assigns a value to a
variable.
assignment operators :
- assigns values from right to left.
- Make code shorter and more readable.
Types Of Assignment Operator :
- Simple Assignment Operator (=)
- Compund Assignment Operators (+=, -=, *=, /=, %=)
4. Examples :
Example 1 : Simple Assignment Operator
Output :
the value of a is 5
#include<stdio.h>
int main(){
int a;
a=5; // assigning 5 to a
printf(“the value of a is %d”,a);
return 0;
}
5. Example 2 : Compund Assignment Operator
Output :
a after += :10
a after *= :20
#include<stdio.h>
int main() {
int a=5;
a+=5; // same as a=a+5
printf(“a after += %d n”,a);
a*=2; // same as a=a*2
printf(“a after *= : %d”,a);
return 0;
}
6. Increment and Decrement Operator :
Increment(++) and decrement(--) operators are used to
increase or decrease
a variables value by 1
These operators are commonly used in
Loops(for,while)
&
Counters
7. 1.Increment Operator(++) :
The increment operator (++) increase the value of a variable by 1
There are two types of increment operators :
1.Pre-Increment(++variable):
Increases the variable’s value before using it in an expression
2.Post-Increment(variable++):
Uses the variables current value in an expression,then increases it
8. Example of Increment Operator
#include<stdio.h>
int main(){
int a=5;
printf(“Pre-increment :%dn”,++a); //increment
first,then print
printf(“Post-increment :%dn”,a++);//prints first then
increment
printf(“Value after Post-Increment:%d”,a);
return 0;
}
output:
Pre-increment :6
Post-increment :6
Value after Post-
Increment:7
9. 2. Decrement Operator (--):
The decrement operator (--) decreases the value of a variable by 1
There are two types of Decrement Operators:
1.Pre-Decrement (--variable):
Decreases the variable’s value before using it.
2. Post-Decrement (variable--):
Uses the variable’s current value in an expression, then decreases it.
10. #include <stdio.h>
int main() {
int a = 10;
printf("Pre-Decrement: %dn", --a); // Decrements first, then
prints (9)
printf("Post-Decrement: %dn", a--); // Prints first (9), then
decrements
printf("Value after Post-Decrement: %dn", a); // Now a=8
return 0;
}
Output:
Pre-Decrement:9
Post-Decrement:9
Value after Post-
Decrement:8
Example of Decrement Operator:
11. Conditional Operator (?:):
The conditional operator is a shorthand for if-else
statements.
also known as the ternary operator.
It allows you to write conditional expressions in a more
concise way.
The conditional operator is faster and more concise than if-
else.
it’s useful for simple conditions like min/max selection and
checking conditions.
12. Syntax :
condition ? expression1 : expression2;
If condition is true (non-zero),
expression1 is executed.
If condition is false (zero),
expression2 is executed.
13. Example 1 :(Maximum and minimum)
#include<stdio.h>
int main() {
int a=10, b=20;
Int min=(a<b) ? a : b; //finds the smaller number
printf(“Minimum value:%dn”,min);
return 0;
}
Output:
Minimum value:10
Since a<b is true ,a is assigned to min
14. Example 2: Checking Even or Odd
#include <stdio.h>
int main() {
int num = 9;
printf("%d is %sn", num, (num % 2 == 0) ? "Even" : "Odd");
return 0;
}
Output:
9 is odd