Monday 15 June 2015

Concatenating Variable Names in C? -


Is it possible to add variable names in C? Specifically, I have a struct that contains 6 similar variables, which are called class1 , class2 , class3 Say etc.

I want to run a loop to assign a value to each variable, but I do not need to see that somehow adding variable name with the value of the loop counter How to do

How can I do this?

When you add yourself an integer suffix to the variable name, it seems that I should use an array

  struct mystruct {int class [6]; }; Int main (zero) {struct mystruct s; Int i; For (i = 0; i & lt; 6; ++ i) {S class [i] = 1000 + i; } Return 0; }   Note:  due to  class  a C ++ compiler will override this if you use this code in C ++ If you plan to compile in the form, then you have to understand a different name for that area. 


No comments:

Post a Comment