I'm having trouble understanding the concept of functions. How exactly are they used, and where do they go? Things like that. Thanks for the help.
I'm having trouble understanding the concept of functions. How exactly are they used, and where do they go? Things like that. Thanks for the help.
here's a usage example
Making functions usually has two parts:Code:#include <stdio.h> int generic(); // The decleration int main() { generic(); } int generic() //The implementation { int example = 15234+21534; return example; }
The decleration (these go in .h files or at the top of source files)
and the implementation (these go in .c files)
The basic two purposes of a function are
-Saving space when a single chunk of code is going to be used multiple times
-Helping readibility
Careful there. Your prototype of:Originally Posted by MadCow257Is saying "generic is a function that returns int and takes any number of arguments".Code:int generic();
If you called that function as generic("potato", 3, 8.5); the compiler wouldn't complain. You should instead use:The compiler then knows generic() takes no arguments.Code:int generic(void);