J
Joe Wright
#include <stdio.h>Merrill said:At the risk of developing a larger reputation as a dullard, I would like to
continue this discussion at a level that I can understand. The following
code, I believe, produces exactly the behavior--with good style--that we're
looking for from K&R2 §5.
#include <stdio.h>
void swap(int *px, int *py);
int main(void){
int a = 3;
int b = 5;
swap(&a, &b);
printf ("a equals %d\n", a);
printf ("b equals %d\n", b);
return 0;
}
void swap(int *px, int *py){
int tmp = *px;
*px = *py;
*py = tmp;
}
Q1) Does anyone think that this is lacking in any fashion?
Q2) If prototype and declaration are not the same thing, then which line
number is which?
MPJ
P.S. I've read this thread, but I simply need to back up a bit.
void swap(int*, int*); /* This is a prototype and declaration */
int main(void) {
int a = 3;
int b = 5;
swap(&a, &b);
printf("a equals %d\n", a);
printf("b equals %d\n", b);
return 0;
}
void swap(int *px, int *py) { /* This is the definition */
int tmp = *px;
*px = *py;
*py = tmp;
}