A function is a named block with a return type, a parameter list, and a body. It is the unit of reuse and of linking. C has no methods and no overloading.
Mental model: the prototype (declaration) is the contract. The definition is the body, exactly once in the program. Callers must see a prototype before the call in modern C (C99+ implicit-int is gone; calling without a prototype is a constraint violation in C23 and a bad idea everywhere).
/* declaration — typically in a header */
int add(int a, int b);
/* definition — one .c file */
int add(int a, int b) {
return a + b;
}
void f(void) takes no arguments. void f() in C means “unspecified arguments” (old style), not “no args.” Write void.int add(int, int);static int helper(void); — internal linkage; not visible from other translation units.Every argument is copied. Mutating a parameter does not mutate the caller’s object unless the parameter is a pointer to that object.
void bump_wrong(int n) { n += 1; } /* caller unchanged */
void bump(int *p) { *p += 1; } /* caller’s int changes */
int x = 1;
bump_wrong(x); /* x still 1 */
bump(&x); /* x is 2 */
const if read-only.return e; converts e to the return type. void functions use return;.int status (0 success, nonzero fail) or a sentinel (NULL, EOF, −1). There are no exceptions.int parse_positive(const char *s, int *out) {
if (s == NULL || out == NULL) {
return -1;
}
/* … */
return 0;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "usage: %s <file>\n", argv[0]);
return 1;
}
}
argc is the count. argv[argc] is a null pointer. argv[0] is the program name (convention).argv[i] is a string. Do not write argv[i] = … unless you know the lifetime.void f() thinking it is void f(void).int and silently mis-called.scanf, malloc later, fopen).print like Java. C uses different names or a format string..c, include the header from the .c (so the compiler checks they match).(void) for empty parameter lists.const T * to read.~ Good luck with your revision! ~