










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











int main() {
number=cubeByValue(number); } int (^) cubeByValue( int n ) { return n * n * n; } number 5 n Before main^ calls cubeByValue^ : undefined int main() {
number = cubeByValue( number );
int cubeByValue( int n ) { return n * n * n; } number 5 n After cubeByValue^ receives the call:
return n * n * n; } int main() {
number = cubeByValue( number ); } number
n After cubeByValue cubes parameter n and before cubeByValue returns to main :
Fig. 7.8 Analysis of a typical call-by-value. (Part 1 of 2.)
int main() {
number = cubeByValue( number ); }
return n * n * n; } number
n After cubeByValue^ returns to main^ and before assigning the result to number: undefined 125 125 int main() {
number = cubeByValue( number ); } int cubeByValue( int n ) { return n * n * n; } number
n After main^ completes the assignment to number: undefined Fig. 7.8 Analysis of a typical call-by-value. (Part 2 of 2.)
Pointers and Arrays
The name of the array is like a constant pointer which contains the address of the first element. Pointers and Arrays
Declaration of a Pointer Variable int y [ 10 ] ; int *yptr ; yptr = y ; yptr is a pointer to integer The array name (y) is actually the address of first element of the array y[ 5 ] yPtr = &y[ 0 ] Explicitly assigns yPtr to address of first element of y
Pointer Expressions and Pointer Arithmetic ļ® Arithmetic operations can be performed on pointers
ļ® 5 element int array on machine with 4 byte ints
pointer variable yPtr y[0] y[1] y[2] y[3] y[4] 3000 3004 3008 3012 3016 location
Pointer Expressions and Pointer Arithmetic ļ® Subtracting pointers
The Relationship Between Pointers and Arrays