[Solved] Understanding garbage collection in C [closed]


Non-static variables (local variables) are indeterminate. Reading them prior to assigning a value results in undefined behavior.

Either initialize the variables:

#include <stdio.h>

int main () {

  int a = 1;
  int b = 2;
  int c = 3;
  int d = 4;
  printf("ta-dah: %i %i %i %i\n", a, b, c, d);

  return 0;
}

Output: ta-dah: 1 2 3 4

Or set them to static:

#include <stdio.h>

int main () {

  static int a;
  static int b;
  static int c;
  static int d;
  printf("ta-dah: %i %i %i %i\n", a, b, c, d);

  return 0;
}

Output: ta-dah: 0 0 0 0

2

solved Understanding garbage collection in C [closed]