Mohammed Thaier
Mohammed Thaier

Reputation: 173

Array with multiple data types

I want to make array for positions (x, y, z)

It would be something like this:

/*Whatever the type*/ array[100] = {(1, 2, 3), (4, 2, 5)....}

How can I do this?

Upvotes: 0

Views: 637

Answers (1)

Rohan Bari
Rohan Bari

Reputation: 7726

To be honest, making a struct makes the program much simplified:

struct location {
    int x;
    int y;
    int z;
};

int main(void) {
    location array[100];

    // Example initialization of the first index
    array[0].x = 10;
    array[0].y = 20;
    array[0].z = 30;

    // Or, even better...

    array[0] = {10, 20, 30};
    .
    .
}

In case you want to manually initialize x, y, z of each, then:

location array[100] = {{1, 4, 3}, {3, 0, 2}, {}, ...}

Note: These values are not required, they are just to demonstrate the initialization.

Upvotes: 2

Related Questions