C Tutorial/printf scanf/printf sign character


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск

" ": Indicates a space for positive values so that positive values and negative values are aligned

#include <stdio.h>
main()
{
    printf("% d\n", 25);
    printf("% d", -25);
}
25
     -25

+ Indicates that i number is printed using a sign character (+ or -).

#include <stdio.h>
main()
{
    printf("%+d\n", -25);
    printf("%+d\n", 25);
}
-25
     +25

Printing a space before signed values not preceded by + or -

#include <stdio.h>
int main()
{ 
   printf( "% d\n% d\n", 547, -547 );
   return 0;
}
547
-547

Printing numbers with and without the + flag

#include <stdio.h>
int main()
{ 
   printf( "%d\n%d\n", 786, -786 );
   printf( "%+d\n%+d\n", 786, -786 );
   return 0;
}
786
-786
+786
-786