TCS Company Programming Variables

Predict the output of following code:
main()
{
int a=2;
switch(a)
{
case 1: printf(“one”);
case 2: printf(“Two”);
// Executable code ; No break statement
case 3: printf(“Three”);
default:printf(“Invalid option”);
}
}

1. onetwothree
2. Invalid option
3. one two
4. None of these

Read Solution (Total 6)

TCS Other Question

Predict the output of following code:
main()
{
int a=2;
if(a-- , --a, a) // if(2, 0, 0) last value 0 →False
printf(“Tom”);
else
printf(“Jerry”);
}

1. Tom
2. Jerry
3. Tom Jerry
4. Error
Guess the output:
main()
{printf(“%d”,​ sizeof('a'));
}
//same as → sizeof(97)
1. 2 or 4
2. 1 or 3
3. Garbage value
4. ASCII value of a