Note that in this program the sum function is used before it is defined. It is also not pre-declared or prototyped. The compiler issues this warning:
Quote:
Compiling...
undeclared.c
C:\Documents and Settings\David\My Documents\My Windows\undeclared\undeclared.c(5) : warning C4013: 'sum' undefined; assuming extern returning int
undeclared.obj - 0 error(s), 1 warning(s)
|
#include <stdio.h>
int main (int argc, char * argv [])
{
printf ("Sum of 2 and 2 is %d\n", sum (2, 2));
}
int sum (int a, int b)
{
return a+b;
} Note from the output that the function performs as written. You cannot do this in C++. There are a number of reasons that C++ is NOT a superset of C, though it seems to be the case for many things. My son has a goodly number of my genes. He is not a superset, though he is both larger and meaner.
Quote:
|
Originally Posted by Output
Sum of 2 and 2 is 4
Press any key to continue
|