Professional Documents
Culture Documents
Unit 4: Expression and Operator: Er. Nipun Thapa
Unit 4: Expression and Operator: Er. Nipun Thapa
If c = 5 and d = 2 then,
Logical AND. True only if all operands are
&& expression ((c==5) &&
true
(d>5)) equals to 0.
If c = 5 and d = 2 then,
Logical OR. True only if either one operand
|| expression ((c==5) ||
is true
(d>5)) equals to 1.
If c = 5 then, expression
! Logical NOT. True only if the operand is 0
!(c==5) equals to 0.
#include<stdio.h>
int main()
{
int n1,n2,larger,smaller;
printf("Enter two number:");
scanf("%d%d",&n1,&n2); // 6 8
larger=n1>n2 ? n1 : n2; // 6>8
printf("The lager is %d",larger);
return 0;
}
#include<stdio.h>
int main()
{
int n1,n2,n3,large1,large2;
printf("Enter three number:");
scanf("%d%d%d",&n1,&n2,&n3); //2 1 4
large1=n1>n2?n1:n2; // large1= 2
large2=large1>n3?large1:n3; // large2=4
printf("The largest value is %d",large2);
return 0;
}
| Bitwise OR
^ Bitwise exclusive OR
~ Bitwise complement
3
4
5
9
10
11
12
13
14
15
Here, the first operand is char type and the other is of type unsigned int.
So, as per rule 6, char data type will be converted to unsigned int during
the operation. Therefore, the final result will be an unsigned
int variable, 65 + 60 = 125.
int main()
{
double x = 1.2;
return 0;
}
Output:
sum = 2
51 Nipun Thapa - BIM2ndC - Unit 4
Type Conversion in Expressions
Advantages of Type Conversion
This is done to take advantage of certain features of type
hierarchies or type representations.
It helps us to compute expressions containing variables of
different data types.