what does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a =...

48
What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }

Upload: anthony-hines

Post on 17-Jan-2016

230 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }

Page 2: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }Ans: a=77 *pa=77

Page 3: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• The variable a is declared to be an integer variable. The variable pa is declared to hold a pointer to an integer. Notice that the name of the second variable is pa. The name does not include the asterisk.

• The variable a is assigned the value 77. Then pa is assigned the address of a. (Another way to say this is that pa is assigned a pointer to a.)

• In the printf() statement, the first value printed comes directly from a. The second value is found by following the pointer in pa. (Another way to say this is that pa is dereferenced.)

Page 4: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a = 77 ; int *pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }

Page 5: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a = 77 ; int *pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }

Ans: a=77 *pa=77

Page 6: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• Like previous except that the statements that declare the variables also initialize them.

Page 7: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a ; int *pa ; pa = &a ; *pa = 77 ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }

Page 8: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a ; int *pa ; pa = &a ; *pa = 77 ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }Ans:a=77 *pa=77

Page 9: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a = 99; int *pa ; int *qa ; pa = &a ; qa = pa ; printf("a=%d *pa=%d *qa=%d\n", a, *pa, *qa ); system("pause"); return 0; }

Page 10: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor? #include <stdio.h> int main( void ) { int a = 99; int *pa ; int *qa ; pa = &a ; qa = pa ; printf("a=%d *pa=%d *qa=%d\n", a, *pa, *qa ); system("pause"); return 0; }

Ans:a=99 *pa=99 *qa=99

Page 11: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Will the following code compile? #include <stdio.h> int main( void ) { int a ; int *pa = &a ; &a = 77 ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }

Page 12: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Will the following code compile? #include <stdio.h> int main( void ) { int a ; int *pa = &a ; &a = 77 ; printf("a=%d *pa=%d\n", a, *pa ); system("pause"); return 0; }Ans: No.

Page 13: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

The statement &a = 77 ; Is not syntactically correct. The operator & means "compute the address of" and makes no sense on the left of an assignment operator.

Page 14: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Will the following code compile and run? #include <stdio.h> int main( void ) { int a = 45 ; int *pa = &a ; printf("a=%d pa=%o\n", a, pa ); /* Inspect this statement */ system("pause"); return 0; }

Page 15: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Will the following code compile and run? #include <stdio.h> int main( void ) { int a = 45 ; int *pa = &a ; printf("a=%d pa=%o\n", a, pa ); /* Inspect this statement */ system("pause"); return 0; }

Ans:Yes. It prints the following : a=45 pa=10577574

Page 16: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• The statement printf("a=%d pa=%o\n", a, pa ) prints the contents of a (an ordinary integer) and then prints the contents of pa (using octal). The variable pa contains a pointer value, and there is little reason to print it out, but it is OK to do so.

• On your computer you will probably see a different value for pa. pa contains the address of a, and that value depends on what choices the compiler made and what is going on inside your computer at the moment.

• You could also have printed out the contents of pa using • printf("a=%d pa=%x\n", a, pa ) which prints the address using

hexadecimal, or even• printf("a=%d pa=%d\n", a, pa ) which prints the same address using

decimal. Of course, the address does not change (the 32 bits of the address do not change) but the characters used to represent those bits on the monitor are different.

Page 17: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ int a = 44 ; int b = 66 ; int *p ; p = &a ; printf("*p=%d\n", *p ); p = &b ; printf("*p=%d\n", *p ); system("pause"); return 0;}

Page 18: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ int a = 44 ; int b = 66 ; int *p ; p = &a ; printf("*p=%d\n", *p ); p = &b ; printf("*p=%d\n", *p ); system("pause"); return 0;}Ans:*p=44 *p=66

Page 19: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• p is a variable, so its contents can change. First it points at a, but then it is changed to point to b.

Page 20: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ int a = 44 ; int b = 66 ; int *pa, *pb ; pa = &a ; pb = &b ; printf("*pa=%d *pb=%d\n", *pa, *pb ); *pa = *pb ; printf("a=%d b=%d\n", a, b ); system("pause"); return 0;}

Page 21: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ int a = 44 ; int b = 66 ; int *pa, *pb ; pa = &a ; pb = &b ; printf("*pa=%d *pb=%d\n", *pa, *pb ); *pa = *pb ; printf("a=%d b=%d\n", a, b ); system("pause"); return 0;}

Ans:*pa=44 *pb=66 a=66 b=66

Page 22: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

The statement *pa = *pb is performed in two steps (as are all assignment statements):

Step 1: The expression on the right of the = is evaluated. *pb evaluates to 66.

Step 2: The expression on the left of the = determines where to put the 66. The *pa says to follow the pointer in pa, so the 66 is put in the variable a, replacing what was there.

Page 23: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ int a = 44 ; int b = 66 ; int *pa, *pb, *pt ; pa = &a ; pb = &b ; printf("*pa=%d *pb=%d\n", *pa, *pb ); /* Swap pointer values */ pt = pa; pa = pb; pb = pt; printf("*pa=%d *pb=%d\n", *pa, *pb ); system("pause"); return 0;}

Page 24: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ int a = 44 ; int b = 66 ; int *pa, *pb, *pt ; pa = &a ; pb = &b ; printf("*pa=%d *pb=%d\n", *pa, *pb ); /* Swap pointer values */ pt = pa; pa = pb; pb = pt; printf("*pa=%d *pb=%d\n", *pa, *pb ); system("pause"); return 0;}Ans:*pa=44 *pb=66 *pa=66 *pb=44

Page 25: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ double a = 123.456 ; double *pa = &a ; printf("a=%lf *pa=%lf\n", a, *pa ); system("pause"); return 0;}

Page 26: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>int main( void ){ double a = 123.456 ; double *pa = &a ; printf("a=%lf *pa=%lf\n", a, *pa ); system("pause"); return 0;}Ans:a=123.456000 *pa=123.456000

Page 27: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• Pointers can point to anywhere in memory, including variables of type double.

Page 28: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

#include <stdio.h>

void myFunction( int x ) { printf(" x=%d\n", x ); x = 123; printf(" x=%d\n", x );}

void main ( void ){ int a = 77; printf("a=%d\n", a ); myFunction( a ); printf("a=%d\n", a ); system("pause");}

Page 29: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

#include <stdio.h>

void myFunction( int x ) { printf(" x=%d\n", x ); x = 123; printf(" x=%d\n", x );}

void main ( void ){ int a = 77; printf("a=%d\n", a ); myFunction( a ); printf("a=%d\n", a ); system("pause");}Ans:a=77 x=77 x=123 a=77

Page 30: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>

void myFunction( int x ) { printf(" x=%d\n", x ); x = 123; printf(" x=%d\n", x );}

void main ( void ){ int a = 77; printf("a=%d\n", a ); myFunction( a+11 ); printf("a=%d\n", a ); system("pause");}

Page 31: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>

void myFunction( int x ) { printf(" x=%d\n", x ); x = 123; printf(" x=%d\n", x );}

void main ( void ){ int a = 77; printf("a=%d\n", a ); myFunction( a+11 ); printf("a=%d\n", a ); system("pause");}

Ans:a=77 x=88 x=123 a=77

Page 32: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?#include <stdio.h>void functionB( int y ) { printf(" y=%d\n", y ); y = 999; printf(" y=%d\n", y );}void functionA( int x ) { printf(" x=%d\n", x ); x = 123; functionB( x ); printf(" x=%d\n", x );}void main ( void ){ int a = 77; printf("a=%d\n", a ); functionA( a ); printf("a=%d\n", a ); system("pause");}

Page 33: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?#include <stdio.h>void functionB( int y ) { printf(" y=%d\n", y ); y = 999; printf(" y=%d\n", y );}void functionA( int x ) { printf(" x=%d\n", x ); x = 123; functionB( x ); printf(" x=%d\n", x );}void main ( void ){ int a = 77; printf("a=%d\n", a ); functionA( a ); printf("a=%d\n", a ); system("pause");}Ans:a=77 x=77 y=123 y=999 x=123 a=77

Page 34: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>

void newFunction( int *p ) { printf(" *p=%d\n", *p ); *p = 123; printf(" *p=%d\n", *p );}

void main ( void ){ int a = 77 ; printf("a=%d\n", a ) ; newFunction( &a ) ; printf("a=%d\n", a ) ; system("pause") ;}

Page 35: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

What does the following code write to the monitor?

#include <stdio.h>

void newFunction( int *p ) { printf(" *p=%d\n", *p ); *p = 123; printf(" *p=%d\n", *p );}

void main ( void ){ int a = 77 ; printf("a=%d\n", a ) ; newFunction( &a ) ; printf("a=%d\n", a ) ; system("pause") ;}

Ans:a=77 *p=77 *p=123 a=123

Page 36: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• The function newFunction() and the caller main() must coordinate how values are passed. The parameter list of newFunction(int *p) must match the arguments of its call, newFunction( &a ).

• A function that has not been written to use pointer values can't be called with pointers. There is no way that main() can call the original function myfunction(int x) that will enable that function to change a.

Page 37: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Does the following code compile? If so, what does it write to the monitor?

#include <stdio.h>

void newFunction( int *p ) { printf(" p=%d\n", p ); /* Note: no * before p */}

void main ( void ){ int a = 77 ; printf("a=%d\n", a ) ; newFunction( &a ) ; system("pause") ;}

Page 38: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Does the following code compile? If so, what does it write to the monitor?

#include <stdio.h>

void newFunction( int *p ) { printf(" p=%d\n", p ); /* Note: no * before p */}

void main ( void ){ int a = 77 ; printf("a=%d\n", a ) ; newFunction( &a ) ; system("pause") ;}

Ans:a=77 p=2293628

Page 39: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• The function newFunction(int *p) was called with the address of a as before. But now newFunction(int *p) calls

• printf(" p=%d\n", p ) which prints the contents of p, which is a pointer. A pointer is (on most systems) a 32-bit value, and printf() will happily print it out. The particular value printed depends on the compiler and the run-time environment, and can't be predicted.

Page 40: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

#include <stdio.h>

void functionB( int *y ) { printf(" *y=%d\n", *y ); *y = 999; printf(" *y=%d\n", *y );}

void functionA( int *x ) { printf(" *x=%d\n", *x ); functionB( x ); /* Note this!! */ printf(" *x=%d\n", *x );}

void main ( void ){ int a = 77; printf("a=%d\n", a ); functionA( &a ); printf("a=%d\n", a ); system("pause");}

Page 41: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

#include <stdio.h>

void functionB( int *y ) { printf(" *y=%d\n", *y ); *y = 999; printf(" *y=%d\n", *y );}

void functionA( int *x ) { printf(" *x=%d\n", *x ); functionB( x ); /* Note this!! */ printf(" *x=%d\n", *x );}

void main ( void ){ int a = 77; printf("a=%d\n", a ); functionA( &a ); printf("a=%d\n", a ); system("pause");}Ans:a=77 *x=77 *y=77 *y=999 *x=999 a=999

Page 42: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• Bugs and more bugs! Look carefully. The parameter x contains a pointer to a. This value is what we want to pass on, and the call functionB( x ) does this. The call

• functionB( &x ) would pass a pointer to x (not what we want). The call functionB( *x ) would pass the value in a , 77, which also would be wrong.

• The call functionB(x) copies the value in x into the parameter y of the function. The function now has a pointer to a. When functionB executes printf(" *y=%d\n", *y ) it follows y and prints out what it points to. Next the function executes

• *y = 999 which follows the pointer in y and stores 999 in the variable a.

Page 43: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Of course, a function can be called several times, with different arguments. What does the following write to the monitor?

#include <stdio.h>

void aFunction( int *p ) { *p = 99; }

void main ( void ){ int a = 44, b = 77 ; printf("a=%d b=%d\n", a, b ) ;

aFunction( &a ) ; printf("a=%d b=%d\n", a, b ) ;

aFunction( &b ) ; printf("a=%d b=%d\n", a, b ) ; system("pause") ;}

Page 44: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

Of course, a function can be called several times, with different arguments. What does the following write to the monitor?

#include <stdio.h>

void aFunction( int *p ) { *p = 99; }

void main ( void ){ int a = 44, b = 77 ; printf("a=%d b=%d\n", a, b ) ;

aFunction( &a ) ; printf("a=%d b=%d\n", a, b ) ;

aFunction( &b ) ; printf("a=%d b=%d\n", a, b ) ; system("pause") ;}

ANS:a=44 b=77 a=99 b=77 a=99 b=99

Page 45: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

In the following, main() calls swap() to reverse the values in the variables a and b. But what really happens?

#include <stdio.h>

void swap( int x, int y ) { int temp;

printf(" x=%d y=%d\n", x, y ) ; temp = x; x = y; y = temp; printf(" x=%d y=%d\n", x, y ) ; }

void main ( void ){ int a = 44, b = 77 ;

printf("a=%d b=%d\n", a, b ) ; swap( a, b ) ; printf("a=%d b=%d\n", a, b ) ; system("pause") ;}

Page 46: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

In the following, main() calls swap() to reverse the values in the variables a and b. But what really happens?

#include <stdio.h>

void swap( int x, int y ) { int temp;

printf(" x=%d y=%d\n", x, y ) ; temp = x; x = y; y = temp; printf(" x=%d y=%d\n", x, y ) ; }

void main ( void ){ int a = 44, b = 77 ;

printf("a=%d b=%d\n", a, b ) ; swap( a, b ) ; printf("a=%d b=%d\n", a, b ) ; system("pause") ;}

Ans:a=44 b=77 x=44 y=77 x=77 y=44 a=44 b=77

Page 47: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

The swap() function in the previous puzzle did not work. Look at the following code (repeated from puzzle 19). Your job is to fix it so that swap() works correctly.

#include <stdio.h>

void swap( int x, int y ) { int temp;

printf(" x=%d y=%d\n", x, y ) ; temp = x; x = y; y = temp; printf(" x=%d y=%d\n", x, y ) ; }

void main ( void ){ int a = 44, b = 77 ;

printf("a=%d b=%d\n", a, b ) ; swap( a, b ) ; printf("a=%d b=%d\n", a, b ) ; system("pause") ;}

Page 48: What does the following code write to the monitor? #include int main( void ) { int a ; int *pa ; a = 77 ; pa = &a ; printf("a=%d *pa=%d\n", a, *pa ); system("pause");

• With the proper changes, main and swap coordinate. main passes pointers to its two variables, so now swap can change them. main passes pointers:

• swap( &a, &b )• and swap follows these pointers:• temp = *x; • *x = *y; • *y = temp;