Pointer Basics: Pointers and Memory, Pointer Types

(ポインタの基礎: ポインタとメモリ配置の関係、型としてのポインタ)

Computing Practice I

9th lecture, June 15, 2017

http://www.sw.it.aoyama.ac.jp/2017/CP1/lecture9.html

Martin J. Dürst

AGU

© 2005-17 Martin J. Dürst 青山学院大学

Today's Schedule

 

ミニテスト

 

Applications of C: Apache httpd

Apache feather logo

 

Written Exam (two weeks ago)

If you have less than 40points, please think very seriously how you can improve.

Exams will be handed back after this lecture.

 

Results of Previous Exercises

08A1 08A2 08B1 08C1 08C2
100 points 96 85 83 60 34
60 points 2 13 15 35 59
errors - - - 3 4
not submitted 1 1 1 1 2

 

About Exercise 08C2

Important criterion for software: Extensibility
(for the Temperature class, e.g. adding a new temperature unit)

Choices for internal representation:

Choices for processing:

Because the internal details of the class are encapsulated, they don't change the externally observable behavior.

 

Usage of Pointers

  1. Low-level address manipulation (memory-mapped devices,...)
  2. Array processing (incl. speedup)
  3. Dynamic memory management
  4. References (argument passing by reference,...など)
  5. Indirection

 

How Memory Works

 

Investigating Memory Layout

 

Operators for Pointers (&/*)

 

Pointer Types

 

Declarations and Definitions of Pointers

 

Examples of Pointer Definitions

int *pi; // pointer to int
char *pc; // pointer to char(acter)
// also pointer to (the start of a) character string
int **ppi; // pointer to pointer to int char a[5]; // array of 5 characters
char *pb[5]; // char *(pb[5])
// array of length 5 of pointers to char(acters)
char (*pc)[5]; // pointer to a (character) string of length 5
char c, a[5], *pc, *pa[5], (*pb)[5]; // only char applies to everything

(see also http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html; challenge: implement as program)

 

Operators for Pointers (+/-)

 

Arrays and Pointers

Example of memory layout for arrays and pointers

 

Explanation about Experiment

 

演習問題について

注: 重要: 全問必須 (全員提出)、全問日曜締切

09A2, 09A3, 09C2: プログラムをシステムに提出、かつ用紙を先生に提出
(09C2 の用紙の最後の締め切りは次回の演習開始)

 

次回の準備

 

Glossary

pointer
ポインタ
address manipulation
アドレス操作
dynamic memory
動的メモリ
reference
参照
argument passing by reference
関数への参照渡し
indirection
間接
extensibility
拡張性
unit
単位
byte sequence
バイト列
byte
バイト
bit
ビット
address
番地、アドレス
address-of operator
アドレス演算子
unary
単項
indirection operator (dereference operator)
間接演算子
scope
スコープ、有効範囲