switch case with variables

This is a discussion on switch case with variables within the C++ Programming forums, part of the General Programming Boards category; Why the following code doesn't give errors when I try to compile with gcc, and....
Code:
#include <stdio.h>
int x ...

One is a compile-time constant (the compiler knows the value of x), the other is a run-time constant. A switch case can only use compile-time constants. To use other kinds of values, just use if...else.