C Tutorial/printf scanf/printf sign character — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 13:32, 25 мая 2010

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

<source lang="cpp">#include <stdio.h> main() {

   printf("% d\n", 25);
   printf("% d", -25);

}</source>

25
     -25

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

<source lang="cpp">#include <stdio.h> main() {

   printf("%+d\n", -25);
   printf("%+d\n", 25);

}</source>

-25
     +25

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

<source lang="cpp">#include <stdio.h> int main() {

  printf( "% d\n% d\n", 547, -547 );
  return 0;

}</source>

547
-547

Printing numbers with and without the + flag

<source lang="cpp">#include <stdio.h> int main() {

  printf( "%d\n%d\n", 786, -786 );
  printf( "%+d\n%+d\n", 786, -786 );
  return 0;

}</source>

786
-786
+786
-786