Set your Publisher ID in src/config/ads.ts to display live ads.
Functions, Prototypes & Storage Classes
Header declarations, pass-by-value, and the static keyword
C requires functions to be declared or defined before they are called. Function prototypes declare the signature in header files (.h), implemented in .c files.
Function Prototypes & Storage Classes
Function Prototype: Informs the compiler of parameter types and return type before the actual implementation is compiled.
static local variables: Retain their value between multiple function invocations across the lifetime of the program, stored in the Data Segment rather than the Call Stack.
static global functions: Restrict visibility strictly to the current translation unit (.c file), acting like a private function in OOP.
#include <stdio.h>
// Function prototype declaration
int getNextSequenceID(void);
int main(void) {
printf("ID: %d\n", getNextSequenceID()); // 1
printf("ID: %d\n", getNextSequenceID()); // 2
printf("ID: %d\n", getNextSequenceID()); // 3
return 0;
}
int getNextSequenceID(void) {
// static variable retains its value between function calls!
static int currentID = 0;
currentID++;
return currentID;
}Set your Publisher ID in src/config/ads.ts to display live ads.
Test Yourself With Exercise
What happens to a local variable inside a C function when declared with the `static` keyword?