Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);

Similar presentations


Presentation on theme: "Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);"— Presentation transcript:

1 Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z); return 1; } x is a pointer to an int follow the pointer at x the address of y

2 Functions and Pointers Call-by-value void f( int x ) { x = 10; return; } #include int main() { int a = 5; f( a ); printf(“%d\n”, a); return 0; }

3 Functions and Pointers Call by reference –Multiple return values void f( int *x ) { *x = 10; return; } #include int main() { int a = 5; f( &a ); printf(“%d\n”, a); return 0; }


Download ppt "Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);"

Similar presentations


Ads by Google