Skip to content

Types

Conversions

Type qualifiers

const

const int *p; //can't modify what p points to
*p = 10; //error
int *const p; //can't modify "p"
p++; //error

volatile

  • Volatile tells the compiler that a value might change behind its back and should be looked up every time. E.g: some kind of hardware timer.
  • “The thing this points at might change at any time for reasons outside this program code.”
volatile int *p;

static

  • In block scope: static with an initializer will only be initialized one time on program startup.
void counter(void){
static int count = 1;
printf("This has been called %d time(s)\n", count);
count++;
}
int main(){
counter(); // This has been called 1 time(s)
counter(); // This has been called 2 time(s)
counter(); // This has been called 3 time(s)
}
  • In file scope: the static variable in this context isn’t visible outside of this particular source file.

extern