Basic Operators
- Which of these have highest precedence?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Order of precedence is (highest to lowest) a -> b -> c -> d.
- What is the output of this program?
public class Result
{
public static void main(String args[])
{
int p,q,r,s;
p=q=r=s=10;
p+=q-=r*=s/=10;
System.out.println(p+" "+q+" "+r+" "+s);
}
}
-
View Hint View Answer Discuss in Forum
None of these
Correct Option: B
Expression will evaluate from right to left.
output: 10 0 10 1
- Which of these lines of code will give better performance?
1. p | 8 + r >> q & 10;
2. (p | ((( 8 * r) >> q ) & 10 ))
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
Parentheses do not degrade the performance of the program. Adding parentheses to reduce ambiguity does not negatively affect your system.
- What is the output of this program?
public class Result
{
public static void main(String args[])
{ int q,r;
int p=q=r=26;
System.out.print(+p);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
output: 26
- What is the output of this program?
public class operators
{
public static void main(String args[])
{
int p = 10;
System.out.println(++p * 5 + " " + p);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Operator ++ has higher precedence than multiplication operator, *, p is incremented to 11 than multiplied with 5 giving 55.
output: 55