2012年8月27日月曜日

開発環境

『実践プログラミング 第3版』 (Steve Oualline (著)、 望月 康司 (監修) (翻訳)、 谷口 功 (翻訳)、 オライリー・ジャパン、1998年、ISBN978-4900900646) I部(基礎編)の4章(基本的な宣言および式)4.13(プログラミング実習)実習4-5を解いてみる。

実習4-5.

コード(TextWrangler)

#include <stdio.h>

int main(){
  float a = 1.2;
  int b = 10;
  char ch = 'c';
  printf("%d\n",a);
  printf("%f\n",b);
  printf("%d\n",ch);
  return (0);
}

入出力結果(Terminal)

$ cc -g -o sample sample.c
sample.c:7:12: warning: format specifies type 'int' but the argument has type
      'double' [-Wformat]
  printf("%d\n",a);
          ~^    ~
          %f
sample.c:8:12: warning: format specifies type 'double' but the argument has type
      'int' [-Wformat]
  printf("%f\n",b);
          ~^    ~
          %d
2 warnings generated.
$ ./sample
1672223504
1.200000
99
$

浮動小数点数を整数が、整数型を浮動小数点数がに使用とすると警告が出たり、出力結果がおかしくなるけど、文字型を整数型にいれても(出力結果は文字じゃなくなるけど)問題ないみたい。

0 コメント:

コメントを投稿