#include <limits.h> を書くと、 定数 INT_MAX が使えるようになる。 これは、int 型で表せる最大の数である。 変数 i にそれを代入して 1 だけ増やすと、 授業でやったように int で表せる最小の整数となり、 それを 1 だけ減らすとまた元の最大の整数となる。 その際、エラーメッセージなどが出ないことに注意。 (それだけのためのプログラム。)
===============================================================================
#include <stdio.h>
#include <limits.h>
main()
{
int i = INT_MAX;
printf("%d\n", i);
++i;
printf("%d\n", i);
--i;
printf("%d\n", i);
}
===============================================================================
すべての ASCII 文字とそのコードを出力するプログラム。 ASCII 文字は十六進の 20 から 7e までである。 また、文字を printf() で出力する際は %c と書く。
===============================================================================
#include <stdio.h>
main()
{
char c;
for (c = 0x20; c <= 0x7e; c++) {
printf("%c %d\n", c, c);
}
}
===============================================================================
const を変更するようなプログラムを書き、 コンパイラがどんな警告を出すか(あるいは出さないか)を見よ。
/ 演算子、% 演算子の負の被演算数に対する結果を調べてみよ。
1 == 1 や 1 > 2 はいくつか、を試すプログラム。
===============================================================================
#include <stdio.h>
main()
{
printf("%d\n", 1 == 1);
printf("%d\n", 1 > 2);
}
===============================================================================
1 + 1e-1 のような、 「整数型+浮動小数点数型」の式が何型かを確かめるプログラム。 正しい出力が得られるのはどちらの行だろうか?
===============================================================================
#include <stdio.h>
main()
{
printf("%d\n", 1 + 1e-1);
printf("%f\n", 1 + 1e-1);
}
===============================================================================