Functions in C
Declaring, defining and calling functions in C; prototypes and header files.
Easy
float average(const int *values, int count); // prototype (declaration)
float average(const int *values, int count) { // definition
long sum = 0;
for (int i = 0; i < count; i++) sum += values[i];
return (float)sum / count;
}
Prototypes go in .h files so other files can call the function. static on a function makes it private to its .c file.
Sub-topics (2)
Call by Value and Call by Reference
C passes copies of arguments; to let a function modify a variable, pass its address with a pointer.
Easy♥ 0🔖 0💬 0
Storage Classes
auto, static, extern and register control a variable's lifetime and visibility.
Intermediate♥ 0🔖 0💬 0
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.