In printf(“%-6d|”, 42), what does the minus sign in the format do?
Correct answer B. It left-justifies 42 within a 6-character field
Explanation
The - flag left-justifies the converted value within its field, so 42 is printed first and followed by four spaces before the bar. Without the flag the padding goes on the left and the number is right-justified. The sign of the value is controlled by the argument, not the flag, and zero padding is requested with the 0 flag, which is ignored when - is present.
Answer checked How we write and check questions
Discussion