codegurukool.com · Free coding tutorials & online compiler

Home › C Tutorial › C scope

C scope

Where names are visible.

Local variables exist only inside their block. Globals are visible everywhere but make code harder to follow.

Example code

#include <stdio.h>
int g = 100;
int main() {
  int x = 5;
  { int x = 9; printf("%d ", x); }
  printf("%d %d\n", x, g);
  return 0;
}

Run this code in the online editor

← Pass by referenceC math functions →