The C pointer operators
- The new operators
&
— adddress of*
— deference->
— array
- The unexpectedly reused operators
[ ]
— with pointer and integer+
— with pointer and integer++
and--
— with pointer+=
and-=
— with pointer and integer if result within array==
and!=
— with two pointers-
— with two pointers in same array>
,>=
,<
and<=
— with two pointers in same array
Why does the following expression depend on the type of p
?
(unsigned long)(void *)(p+1) - (unsigned long)(void *)p
More facts about arrays
- The declaration
int P[500]
implies thatP
is anint * const
P[i]
is also*(P+i)
P[i]
is also*(int *)((void *)P+i*sizeof(*P))
C and memory
C presents a low-level address-based view of memory.
- C memory allocation — heap and stack
- C
struct
andunion
- C arrays vs FORTRAN — row vs column major and initial index
- C arrays vs Java arrays — pointers to pointers ...
- My old notes on arrays an pointers
- Ugly allocation example
- Pointer arithmetic example
// static allocation double sPressure[500][500][100] ; // dynamic allocation double (*dPressure)[500][100] ; dPressure = malloc(500*500*100*sizeof(double)) ; // Java style double ***jPressure ; // requires a loop to initialize
A look at the pointer questions from old exams
You must draw it to understand it!
- Spring 2017 final — pp 10
- Fall 2016 final — pp 11–12
- Fall 2015 final — pp 10–11
- Fall 2014 final — pp 9–10