Test your understanding of return values, pass-by-value, void functions, and prototype declarations.
int add(int a, int b) { return a + b; } int main(void) { printf("%d\n", add(3, 7)); return 0; }
add(3, 7) receives a=3, b=7 and returns 3 + 7 = 10.void change(int x) { x = 100; } int main(void) { int a = 5; change(a); printf("a = %d\n", a); return 0; }
change, x is a copy of a.x does not affect the original a, so it remains 5.void greet(void) { printf("Hello!\n"); return 1; }
void function cannot return a value. return 1; is a compile error.return; (no value).#include <stdio.h> int main(void) { printf("%d\n", square(5)); return 0; } int square(int n) { return n * n; }
square is defined after main.square when it's called, producing an implicit-declaration warning or error.int square(int n); before main, or place the function before main.