Here is an example program that I wrote. I want to understand what "return 0;" is, and why I need it and what it does.
A friend answered this above question with:
"in standard c, every function must have a return type. main returns an integer to the OS, and every other function can optionally return any type to where it was called at. if you dont need to return anything, you specify void. (for example, you can have a function that takes two arguements and adds them together, then returns an int as the result)"
I dont understand most of this ^
Code:
#include <stdio.h>
int main(void)
{
char age = 'A';
printf("Then he said %d\n", age);
return 0;
}
Here is another example program, how come in the function I made I did not have to write "return 0;" but in the main function I did?
And how come I had to write "void" before "show(void);", because for the main funtion I dont have void written before it, but at the same time its returning something I guess? Where void doesnt need to return something, but what does return mean, as I think physical or some output....This is where I get confused.
Code:
#include <stdio.h>
void show(void);
int main(void)
{
char *phrase;
phrase = "For he is a jolly good fellow!";
printf("%s\n%s\n%s\n",phrase,phrase,phrase);
show();
return 0;
}
void show(void)
{
printf("Which nobdoy can deny!\n");
}