'Is it possible to write different types of elements in the array?

I learn C programing now. Is it possible to write both numbers and letters in an array? Can you give an example if possible?

c


Solution 1:[1]

You can put different types into a union but you also need to remember what type you put in there. You can use something like this:

enum Kind { INT, FLOAT };
typedef struct {
    enum Kind kind;
    union {
        int i;
        float f;
    }
} Mixed;
Mixed m[1234];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Goswin von Brederlow