TCS
Company
Programming
Basics
Predict the output of following code:
main()
{
int a=100,b=300;
if(a>50)
// No braces, so only one immediate statement is part of if
a=200 ;
b=400;
printf(“%d”,b);
}
1. 400
2. 300
3. 100
4. Error
Read Solution (Total 7)
-
- Output is 400
- 6 years agoHelpfull: Yes(4) No(0)
- 400
first check if condition 100>50 true then it will go into if block only a=200 is considered into if block .but 400 is override in b - 6 years agoHelpfull: Yes(1) No(0)
- Answer is option 400
Inside the if block - 3 years agoHelpfull: Yes(1) No(0)
- Output is 400
- 6 years agoHelpfull: Yes(0) No(0)
- B value is overriden so ans 400
- 6 years agoHelpfull: Yes(0) No(0)
- Option 1
b = 400
Since the if condition accepts only one statement below it provides that there is no opening or closing braces, b value is printed as 400 according to the flow of the c program - 6 years agoHelpfull: Yes(0) No(0)
- 400 because there are no braces.
- 2 years agoHelpfull: Yes(0) No(0)
TCS Other Question