While reading about printf(),I found that it can print numbers as positive or negative as desired by the user by following code(for -).But the code doesnt work and the output is a positive value.Please mention where the error is.Thanks
#include<stdio.h>
int main()
{
printf (" %-d\n", 1977);
return 0;
}
From your comments it looks like you misread this page. The
-and+specifiers do two completely different things, and neither does what you think ‘-‘ should do.As others have noted,
-does left justification. The+specifier prints positive numbers with a leading plus sign (and negative numbers still get a leading minus sign):outputs: