開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C++ (プログラミング言語)
- g++(コンパイラ)
C++実践プログラミング (スティーブ オウアルライン (著)、Steve Oualline (原著)、Steve Oualline(原著)、望月 康司(翻訳)、クイープ(翻訳) 、オライリー・ジャパン)のⅢ部(高度な型とクラス)の15章(シンプルなポインタ)、15.7(プログラミング実習)、実習 15-1を解いてみる。
その他参考書籍
- C++プログラミング入門 (グレゴリー サティア (著)、ダウグ ブラウン (著)、Gregory Satir (原著)、Doug Brown (原著)、望月 康司 (翻訳)、谷口 功 (翻訳)、オライリージャパン)
実習 15-1
コード(BBEdit, Emacs)
sample267_1.cpp
#include <iostream> const int SIZE = 10; int nums[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int *nums_ptr; void p(int nums[]) { int i; for (i = 0; i < SIZE; ++i) { std::cout << nums[i] << ' '; } std::cout << '\n'; } int main(int argc, char *argv[]) { p(nums); nums_ptr = nums; while (nums + SIZE != nums_ptr) { *nums_ptr = 0; ++nums_ptr; } p(nums); return (0); }
Makefile
# # FSFのg++コンパイラ用のMakefile # CC=g++ CFLAGS=-g -Wall all: sample267_1 sample267_1: sample267_1.cpp ${CC} ${CFLAGS} -o sample267_1 sample267_1.cpp clean: rm sample267_1
入出力結果(Terminal)
$ make && ./sample267_1 g++ -g -Wall -o sample267_1 sample267_1.cpp 1 2 3 4 5 6 7 8 9 10 0 0 0 0 0 0 0 0 0 0 $
0 コメント:
コメントを投稿