Teaching const

Ed Kaulakis edk at gryphon.CTS.COM
Mon Apr 18 01:51:00 AEST 1988


> To teach this, it is probably easiest to draw the old memory 'boxes' and
> show what is held where.  For instance, (sizeof(int)==2, sizeof(int*)==4):
> 
> int * const a;    ("a" is located @ 100 and contains address 200)
> int b[1];         ("b" is located @ 104, "b"'s value is 104)
> 
> *a = *b;  (value taken from 104, put in address @100)
> 
> 100                         200
> +-+-+-+-+                   +-+-+
> | 200   |                   |*a |
> +-+-+-+-+                   +-+-+
> 104
> +-+-+
> | 0 |
> +-+-+
> 
> Craig
> -- 
> Craig Schmackpfeffer  @ S.R. Systems
> {allegra,rutgers,ames}!rochester!srs!craig

Uuuh... How did a get that 200 value? A const pointer declaration without
an initializer seems somehow odd to me...



More information about the Comp.lang.c mailing list