TCS
Company
Programming
Definition
Predict the output of following code:
main()
{
int a=2000;
printf(“%2d”,a); //format specification
}
1.2000
2. 20
3. 4000
4. Garbage value
Read Solution (Total 14)
-
- %2d will print the parameter with at least 2 characters
Since the value of a contains 4 digits so output will be same as the value
i.e., 2000 - 6 years agoHelpfull: Yes(7) No(1)
- %2d will give the atleast two character space when the value is in decimals. but it is in normal integer form so it gives the same result as 2000
(1) 2000 is the correct answer - 6 years agoHelpfull: Yes(4) No(0)
- 20 is the ans...bcoz it has given as "%2d"
- 6 years agoHelpfull: Yes(3) No(5)
- ans. will be 1
bcoz %2d creates space 2 space before the number - 6 years agoHelpfull: Yes(3) No(0)
- %2d outputs a decimal (integer) number that fills at least 2 character spaces, padded with empty space.
Thus, correct option is 1) 2000 - 6 years agoHelpfull: Yes(2) No(0)
- ans:- 2000 no data will be loss.
- 6 years agoHelpfull: Yes(2) No(0)
- 20 is the right ans. Because %2d means 2 character show in the output
- 6 years agoHelpfull: Yes(1) No(2)
- 2000(%2d prints a number with two spaces )
- 6 years agoHelpfull: Yes(1) No(0)
- 2000 as 2d is format specifier only
- 6 years agoHelpfull: Yes(1) No(0)
- %2d represents the first 2 digits. So the output will be 20
- 6 years agoHelpfull: Yes(0) No(3)
- Option 2 20.upto 2 digits
- 6 years agoHelpfull: Yes(0) No(0)
- 1)2000 because of %2d.
- 6 years agoHelpfull: Yes(0) No(0)
- It prints 2000
- 4 years agoHelpfull: Yes(0) No(0)
- %2d can only take to maximum value
so a = 2000
then the O/P WILL BE 20 - 2 years agoHelpfull: Yes(0) No(0)
TCS Other Question