Hi, thank you for the help.
I know now that main has to be an int, but i dont really understand why. Is it because the program always returns a number? Is this going back to return 0 means the program is completed sucessfully and none zero is an error. What exactly is the porpose of the int main, just to signify the start of the body of the code?.
For part two, am i right in saying that the & sign points to the location of the variable instead of the actual variable itself?
Finally for part three the code is as follows:
Code:
#include <stdio.h>
int mult ( int x, int y );
int main()
{
int x;
int y;
printf( "Please input two numbers to be multiplied: " );
scanf( "%d", &x );
scanf( "%d", &y );
printf( "The product of your two numbers is %d\n", mult( x, y ) );
getchar();
}
int mult (int x, int y)
{
return x * y;
}
However since it is being defined at the start (because the program executes from the top), would it not be possible to code it like this:
Code:
#include <stdio.h>
int mult ( int x, int y );
int main()
{
int x;
int y;
printf( "Please input two numbers to be multiplied: " );
scanf( "%d", &x );
scanf( "%d", &y );
printf( "The product of your two numbers is %d\n", mult( x, y ) );
getchar();
}
int mult
{
return x * y;
}
I have removed a portion of the code because it is already being defined at the start of the code. Is this not possible? It seems like its defining it twice.
Again thank you for your help, im sorry my questions are probably dumb but ive been reading the tutorials on this site and some things are still not clear.