TCS
Company
Programming
Arrays
Predict the output of following code:
main()
{
int x,a=10;
x=9*5+ 7/3 -6+a; //45+2-6+10 = 51 // 7/3 =2 int division
printf(“%d”,x);
}
1. 51
2. 51.5
3. 31
4. None of these
Read Solution (Total 12)
-
- 51 is the answer
- 6 years agoHelpfull: Yes(4) No(0)
- X=45+2-6+10
X=51 - 6 years agoHelpfull: Yes(1) No(0)
- '*' and '/' have more precedence than '+' and '-'
'*' and '/' have same precedence but their associativity is left to right,so first 9*5=45 will get evaluated then 7/3=2
'+' and '-' have same precedence and also have same associativity
so 5+2-6+10=51 - 5 years agoHelpfull: Yes(1) No(0)
- 51 is the answer
- 5 years agoHelpfull: Yes(1) No(0)
- 51 is the answerr
- 4 years agoHelpfull: Yes(1) No(0)
- ans:51 by the BODMAS rule, x performs the division first and 7/3=2 takes int value ,after performoing all x gets the values as 51
- 6 years agoHelpfull: Yes(0) No(0)
- 51,using BODMAS rule
- 6 years agoHelpfull: Yes(0) No(0)
- None of these
By basic BODMAS rule - 6 years agoHelpfull: Yes(0) No(0)
- Follow the precedence.means first divison operation, and( *) , and ( - ), and then addition (+). So answer is 51.
- 6 years agoHelpfull: Yes(0) No(0)
- Bodmas rule: first addn then subn so ans is 31
- 6 years agoHelpfull: Yes(0) No(0)
- Follow the precedence.means first divison operation, and( *) , and ( - ), and then addition (+). So answer is 51.33 Then Given Option Answer is None of These.
- 6 years agoHelpfull: Yes(0) No(0)
- none of these......u can compile and see;
- 5 years agoHelpfull: Yes(0) No(2)
TCS Other Question