%d for decimal,
%o for oct-decimal and
%x for hex-decimal notation.
#include "stdio.h"
int main(void)
{
int a = 65, b = 0101, c = 0x41;
long l = 65L, m = 0101L, n = 0x41L;
printf("\t%%d\t%%o\t%%x\n");
printf("(a)\t%d\t%o\t%x\n", a, a, a);
printf("(b)\t%d\t%o\t%x\n", b, b, b);
printf("(c)\t%d\t%o\t%x\n", c, c, c);
printf("\t%%ld\t%%lo\t%%lx\n");
printf("(l)\t%ld\t%lo\t%lx\n", l, l, l);
printf("(m)\t%ld\t%lo\t%lx\n", m, m, m);
printf("(n)\t%ld\t%lo\t%lx\n", n, n, n);
return 0;
}
65 や 0101,0x41 は「整数定数」と呼ばれているものです(*)。接尾子 L は long型という意味です。65 は10進数の65,0101 は8進数で101,0x41 は16進数で41という意味です。また,printf関数内の変換指定子ですが,long型変数の出力には,%d や %o の d や o の前に l を付します。また,\t は水平タブです。これは文字定数に使えるエスケープ文字です。
実行結果です。
%d %o %x
(a) 65 101 41
(b) 65 101 41
(c) 65 101 41
%ld %lo %lx
(l) 65 101 41
(m) 65 101 41
(n) 65 101 41
すべての変数が整数 65 を意味しています。
[Quote]:
http://okuyama.mt.tama.hosei.ac.jp/unix/C/slide15-1.html