C - array in array

I want to have a static array with arrays in it. I know that you can make a regular array as follows:

int test[] = {1,2,3,4};

But I want to do something like this (Xcode gives me a bunch of warnings, etc.):

int test[] = {{1,2}, {3,4}};

In python, this will be:

arr = [[1,2], [3,4]];

What is the right way to do this?

+3
source share
3 answers

To have a multidimensional array, you will need two levels of arrays:

int test[][] = {{1,2}, {3,4}};

However, it will not work , since you need to declare the size of the internal arrays, except for the last:

int test[2][] = {{1,2}, {3,4}};

Or, if you need even more stringent type safety:

int test[2][2] = {{1,2}, {3,4}};
+6
source

You can use typedeflike this

typedef int data[2];
data arr[] = {{1,2},{3,4}};

, ""

+2

2- :

int test[][] = {{1,2}, {3,4}};

. C. , , LiraNuna.

0
source

Source: https://habr.com/ru/post/1734657/


All Articles