開発環境
- OS: macOS High Sierra - Apple
- Text Editor: Emacs
- コンパイラー: LLVM/Clang, GCC(gcc)
- プログラミング言語: C
Head First C ―頭とからだで覚えるCの基本 (David Griffiths (著)、Dawn Griffiths (著)、中田 秀基 (監修)、木下 哲也 (翻訳)、オライリージャパン)の2章(メモリとポインタ - 何を指しているの?)、コンパスマグネット(p. 49)を取り組んでみる。
コンパスマグネット(p. 49)
Makefile
CC = cc all: sample run sample: sample.c $(CC) sample.c -o sample run: sample ./sample
コード
#include <stdio.h>
void go_south_east(int * lat, int * lon) {
puts(__func__);
*lat -= 1;
*lon += 1;
}
void p(int lat, int lon) {
printf("停止!現在地:[%i, %i]\n", lat, lon);
}
int main() {
int latitude = 32;
int longitude = -64;
p(latitude, longitude);
go_south_east(&latitude, &longitude);
p(latitude, longitude);
}
入出力結果(Terminal)
$ make cc sample.c -o sample ./sample 停止!現在地:[32, -64] go_south_east 停止!現在地:[31, -63] $
0 コメント:
コメントを投稿