If you can't (or don't want to ) use an array, you can assign the variables to a pointer array:
Code:
#include <stdio.h>
int main() {
int a=1, b=4, c=9, *ray[3], i;
ray[0]=&a; ray[1]=&b; ray[2]=&c;
for (i=0;i<3;i++) if (*ray[i]==4) printf("Found.\n");
return 0;
}
ps. I think you should use brackets around each truth test of this sort:
Code:
if((x == 0) && (y == 0) && (z == 0))
You DEFINATELY should not be enclosing the variable names in single quotes('x', 'y','z'); the only reason this compiles and runs is because you are in effect testing the ASCII values (qv.) of a character. That means your condition tests had absolutely nothing to due with any int variables named x, y, or z.
A quick demonstration of this principle:
Code:
#include <stdio.h>
int main() {
if ('a' == 97) printf("True");
return 0;
}
Notice there is no variable named a, but the ASCII value of 'a' is 97. Even if you add "int a=5" at the beginning, the value of 'a' is 97, so the condition will still evaluate as true (ie, the character 'a' and a variable, a, are not the same thing).