TCS
Company
Programming
Output
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
Read Solution (Total 4)
-
- sizeof return the size. as char is internally stored as integer just 2 or 4 depending on the machine architecture.
- 6 years agoHelpfull: Yes(12) No(0)
- sizeof return the datatype size , so char has 1 byte value
- 6 years agoHelpfull: Yes(1) No(2)
- answer is option 1
- 6 years agoHelpfull: Yes(1) No(0)
- option 1 because it considers the size of char
- 4 years agoHelpfull: Yes(0) No(0)
TCS Other Question
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
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