Just to clarify a few things that may not be clear.
The "int main()" or "void main()" and the return value are linked.
so if you use "
int main()", at the end of the main function you need to return an integer - return 0;
Code: Select all
int main() {
funct_1();
return 0;
}
or if you use "
void main()", at the end of the main function you need to return an integer - return 0;
Code: Select all
void main() {
funct_1();
}
see how void doesnt have a return value... also this doesnt comply with C standards, and you shouldnt do it.
The return value can be used to say if the program exited correctly. This is commonly used as 0, and if you had a check in the program somewhere that had to exit the program you could use return 1.
Code: Select all
int main() {
if (someValidCheck() == false) {
return 1;
}
else {
// rest of the program
other_functs();
}
return 0;
} // end main
also, if it helps, use comments to show yourself where the closing brackets go. It helps for programs with lots of loops:
code with 3 seperate loops executed after each other
Code: Select all
int main() {
for (i = 1; i <= 10; i++) {
...code...
} // end i loop
for (j = 1; j <= 10; j++) {
...code...
} // end j loop
for (k = 1; k <= 10; k++) {
...code...
} // end k loop
} // end main
code with 3 NESTED loops executed at the same time...
Code: Select all
int main() {
for (i = 1; i <= 10; i++) {
...code...
for (j = 1; j <= 10; j++) {
...code...
for (k = 1; k <= 10; k++) {
...code...
} // end k loop
} // end j loop
} // end i loop
} // end main
BTW, the code isnt exactly right, just intended to show the things Ive mentioned. Hope it helps. (in a hurry so couldnr explain it as well as I'd have liked!!)
HaQue