開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C (プログラミング言語)
- Clang (コンパイラ)
C実践プログラミング 第3版 (Steve Oualline (著)、 望月 康司 (監訳) (翻訳)、谷口 功 (翻訳)、オライリー・ジャパン)のⅡ部(単純なプログラミング)の13章(単純なポインタ)、13.1(ポインタ)、13.2(関数引数としてのポインタ)、13.3(constポインタ)、13.4(ポインタと配列)、13.5(ポインタを使用しない方法)、13.6(ポインタを使用した文字列分割)、13.6(ポインタを使用した文字列分割)、13.7(ポインタと構造体)、13.8(コマンド業引数)、13.10(プログラミング実習)、実習 13-1を解いてみる。
その他参考書籍
- プログラミング言語C 第2版 ANSI規格準拠 (B.W. カーニハン D.M. リッチー (著)、 石田 晴久 (翻訳)、共立出版)
- プログラミング言語Cアンサー・ブック 第2版 (クロビス・L.トンド、スコット・E.ギンペル(著)、矢吹 道郎(翻訳))
実習13-1.
コード
sample.c
#include <stdio.h> int main() { int size = 10; int nums[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int *nums_ptr; int i; nums_ptr = nums; void display(int nums[], int length); display(nums, size); for (i = 0; i < size; i += 1){ *nums_ptr = 0; nums_ptr++; } printf("書き換え後\n"); display(nums, size); return (0); } void display(int nums[], int length) { int i; for (i = 0; i < length; i += 1){ printf("%d: %d\n", i, *nums); nums++; } }
makefile
CC=cc CFLAGS=-g sample: sample.c $(CC) $(CFLAGS) -o sample sample.c clean: rm -f sample
入出力結果(Terminal)
$ ./sample 0: 0 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 書き換え後 0: 0 1: 0 2: 0 3: 0 4: 0 5: 0 6: 0 7: 0 8: 0 9: 0 $
0 コメント:
コメントを投稿