Professional Documents
Culture Documents
Operators and Assignments and Flow Control
Operators and Assignments and Flow Control
Operators and Assignments and Flow Control
assignments
Operators and assignments
Increment/decrement
Arithmetic operators
Concatenation
Relational operators
Equality operators
Bitwise
Short circuit
Assignment
Conditional operators
Increment and decrement operators
Output c.e.PLP
Output=11
byte b=10;
b=(byte)(b+1)
SOP(b);//11
ARITHMATIC OPERATOR
+,-,*,/,%
If we apply any arithmetic operator between two variables a and b the result
type is always
Byte+byte=int
Byte+short=int(int,byte,short)
Int+long=long(int,int,long)
Long+float=float
Char+char=int
Incase of integral arithmetic(byte,short,int,long) there is no way to represent
infinity and undefined result.
Incase of floating point arithmetic there is way to represent infinity and
undefined result.
Output?
10/0=A.E
10/0.0=infinity
0/0=A.E.
0/0.0=NaN
The only operators that cause A.E. are / and %
String concatenation operator(+)
s1 hello
s2
hello
SOP(~4)
Output -5
explicit
implicit
Compiler is responsible
Upcasting
No loss of information
Following are various possible implicit typecasting
byte short
int floa
long double
t
char
Ex-int x=‘a’;
SOP(x)
Explicit
Programmer is responsible
Bigger to smaller datatype variable
Downcasting
Chance of loss of information
byte short
int floa
long double
t
char
byte b=(byte)130;
SOP(b); -126
130----00000000 ……..10000010
……….10000010(8 bit)======= -
1111101+1=1111110=-126
Assignment operators
Simple
int x=20;
Chained
int a,b,c,d;
a=b=c=d=20;
Int a=b=c=d=20;
int b,c,d;
int a=b=c=d=20;
Compound
When assignment operator is mixed with some other operator (a+=30;)
10101110 x>>2
--101011
Every label should be valid compile time constant, variable are not allowed
Expressions are allowed for switch argument and case label shold be a constant
Duplicate case labels are not allowed
FALL THROUGH INSIDE SWITCH
With in switch statement if any case is matched from that case onwards all statements
will be executed until break statement or end of switch.
Switch(x)
{
Case 0:
SOP(“0”);
Case 1:
SOP(“1”);
Break;
Case 2:
SOP(“2”)
Default:
SOP(“def”)
}
X=0 output 0,1
X=1 output 1
X=2 output 2,def
while