C - Integer Output, width, alignment, padding

Description

Integer Output, width, alignment, padding

Demo

#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>

int main(void)
{
  int k = 678;/*  www.ja  v  a  2s . c  o  m*/

  // Display formats as heading then display the values
  printf_s("%%d   %%o   %%x   %%X\n");
  printf_s("%d  %o  %x  %X\n", k, k, k, k);
  printf_s("\n|%%8d       |%%-8d      |%%+8d      |%%08d      |%%-+8d     |\n");
  printf_s("|%8d  |%-8d  |%+8d  |%08d  |%-+8d  |\n", k, k, k, k, k);
  return 0;
}

Result

The following code

printf_s("%d  %o  %x  %X\n", k, k, k, k );

outputs decimal, octal, and two varieties of hexadecimal for the value 678, with the default width specification.

Related Topic