In the snippet below:
#include <stdio.h>
void swap (int*, int*);
// ^----(1)
int main (void) {
int a = 21;
int b = 17;
swap(&a, &b);
printf("a = %d, b = %d\n", a, b);
return 0;
}
void swap (int *pa, int *pb) {
// ^----(2)
int t = *pa;
*pa = *pb;
*pb = t;
return;
}
Which of these between (1) and (2) can be considered as a function prototype?
Yes, but only if the compiler has seen it. The compiler reads from top to bottom
The function prototype serves as a function declaration. The function header + body serves as a function definition, and since all definitions are declarations, it’s also a declaration