2013/06/08(Sat)
C言語でHello Worldプログラムを作る
C言語を使って、端末に「hello, world」と表示させるプログラムを作りました。
テキストエディタでhello.cというファイルを作成。
以下のコードを書く。
#include <stdio.h>
main()
{
printf("hello, world\n");
}
端末を開いて、以下のコマンドを実行しコンパイルする。
$ gcc hello.c
すると新たにa.outという実行可能なファイルができるので、
$ ./a.out
というコマンドを走らせる。
結果は…
$ hello, world
初めてのCプログラムができました。
コードの内容です。
#include <stdio.h>で標準入力ライブラリを読み込み、
main()という引数なしの関数を定義し、printf関数で文字列を印字してます。
\nは改行記号です。
参考図書:
- プログラミング言語C 第2版 ANSI規格準拠
(www.amazon.co.jp)



