TCS
Company
Programming
Predict the output of following code:
main()
{
int sum;
char ch1='a';
char ch2='b';sum=ch1+ch2; // ascii sum; sum = 97+98 = 195
printf(“%d”,sum);
}
1. Error
2. 195
3. 201
4. “ab”
Read Solution (Total 4)
-
- ch1 = 97 ASCII Value and ch2 = 98
hence, the sum is 195 - 6 years agoHelpfull: Yes(5) No(0)
- 2. 195 as sum = 97+98 = 195 ASCII VALUE of ch1 and ch2
- 6 years agoHelpfull: Yes(1) No(0)
- 195 as it given on question and sum is of integer type
- 6 years agoHelpfull: Yes(1) No(0)
- answer is 195
- 6 years agoHelpfull: Yes(0) No(0)
TCS Other Question
Predict the output of following code:
main()
{
int a=b=c=d=10;
// error: ‘b’ , ‘c’, ‘d’ undeclared
printf(“%d,%d,%d,%d”,a,b,c,d);
}
1. Error
2. 10,10,10,10
3. GV,GV,GV,10
4. GV,GV,GV,GV
Predict the output of following code:
main()
{
float a=1.1;
double b=1.1;
if(a==b) // datatype is different cant be compared; hence result will be 0
printf(“equal”);
else
printf(“not equal”);
}
1. equal
2. not equal
3. Error
4. equal not equal