How to check if element of array is int or float?

arrays, c

Solution

With the caveat that this is a lot of sophistication for a “feature” that you are only going to use while debugging your program, you can use C11's `_Generic` construct:

_Generic(values[0], int: 0, float:1, default:2)

What you should probably do instead that would be more consistent with your intentions is conditional compilation:

#define FLOAT_CASE

#ifdef FLOAT_CASE
float values[] = {88.5f, 56.5f, 100.0f, 2.234f, 88.12f};
#else
int values [] = { 88, 56, 100, 2, 25 };
#endif

... // all the code that is independent of the type of values here

for(i; i < 5; ++i)
#ifdef FLOAT_CASE
  printf("%f ", *(values + i));
#else
  printf("%d ", *(values + i));
#endif

Problem

I have 2 arrays, one is commented, I would like to make universal printf that will plot the values: ``` int values [] = { 88, 56, 100, 2, 25 }; //float values[] = {88.5f, 56.5f, 100.0f, 2.234f, 88.12f}; if (value[0] is int) { for(i; i < 5; ++i) printf("%d ", *(values + i)); } else { for(i; i < 5; ++i) printf("%f ", *(values + i)); } ``` Is there any way to check it? For example when I wanted to see if element is char or int then I used sizeof

Original source