No, you can't do this. (Note: you might be able to pull it off with some sort of horrid memory map, don't do it). You generally want to avoid dynamically referencing variables by name even if the language allows it. It makes understanding the code very difficult. What you want instead is an array or hash table to store and retrieve data in pairs.
If the variables are simply numbered var1, var2, var3... then instead of using individual variables, put the values in an array.
int vars[] = { 23, 42, 99 };
for( int i = 0; i < 3; i++ ) {
printf("vars%d: %d\n", i, vars[i]);
}
If the variable names are not numbers, or the numbers are not contiguous, then the general idea is to use a hash table. This is like an array, but instead of using numbers of the index it uses strings. Lookup is fast, but it inherently has no order.
C doesn't have hashes built in, so you'll have to use a library like Gnome Lib.
#include <glib.h>
#include <stdio.h>
int main() {
/* Init a hash table to take strings for keys */
GHashTable *vars = g_hash_table_new(g_str_hash, g_str_equal);
/* For maximum flexibility, GHashTable expects the keys and
values to be void pointers, but you can safely store
integers by casting them */
g_hash_table_insert(vars, "this", (gpointer)23);
g_hash_table_insert(vars, "that", (gpointer)42);
g_hash_table_insert(vars, "whatever", (gpointer)99);
/* And casting the "pointer" back to an integer */
printf("'this' is %d\n", (int)g_hash_table_lookup(vars, "this"));
g_hash_table_unref(vars);
return 0;
}
Here's a good tutorial on using Gnome Lib.
vars_array[VAR1]dlopen() / dlsym(), but it's a terrible idea (other than for just funnin' around).