Got it but i needs more practiceThe issue is with {5,6}, remove that and see if you can see how it works.
#include<stdio.h>
int main()
{
int array[2][3] = {{1, 2, 3}, {4, 5, 6 }};
return 0;
}
C (and most, but not all languages) store arrays in "row major" order. So { {row 0}, {row 1}, {row 2} }. Therefore your initializer is for an array with 3 rows and 2 columns, but your declaration is for 2 rows and 3 columns.I have declared array that can store six numbers. I've one message while trying to compile program in C language. look's like I'm storing more numbers than array length. I don't understand why red mark is showing before number five
View attachment 274283
I don't understand this paragraph, can you please clarify. You have initialized the array but you have not defined the array index. My guess is that if index is not defined, the compiler will allocate default memory for the array elements. but what will be the advantageThe general recommendation when providing an initializer is to not give explicit dimensions.
int array[][] = {{1,2}, {3,4}, {5,6}};
The advantage is that the compiler will allocate the proper amount of memory for the array initializer without you having to count up the rows and columns and then keep updating the dimensions as you make changes to the initializer.I don't understand this paragraph, can you please clarify. You have initialized the array but you have not defined the array index. My guess is that if index is not defined, the compiler will allocate default memory for the array elements. but what will be the advantage
In three dimensional array we have tables, rows and columnsYou are trying to define a multi-dimensional array:
array[4][3][2]
Think of this as 4 tables, 3 rows, 2 columns.
Create 4 tables first:
int array[4][3][2] = { { }, { }, { }, { } };
https://forum.allaboutcircuits.com/threads/whats-a-tensor.111821/post-864670In three dimensional array we have tables, rows and columns
If I add another index,
int array[5][4][3][2];
Now it has become a 4 dimensional array, what does [5] represent?
There's no set terminology (even 'tables', 'rows', and 'columns' are not fixed in stone). Some common terms for higher dimensions are chapters, books, volumes, collections. This is drawing upon how large sets of textual material might be organized in a library.In three dimensional array we have tables, rows and columns
If I add another index,
int array[5][4][3][2];
Now it has become a 4 dimensional array, what does [5] represent?
Your initializer is for a four dimensional array since you have four nested levels of curly braces.I don't find the reason of warning message in line 8, 12 and 16. What's wrong with that View attachment 274342
It's fine now, no warningSorry. It’s my error in the instructions I provided.
You don’t need braces around the values.
#include<stdio.h>
int main()
{
int array[4][3][2] =
{
{
{ 1, 2}, {3, 4}, {5, 6}
},
{
{ 7, 8}, {9, 10}, {11, 12}
},
{
{ 13, 14}, {15, 16}, {17, 18}
},
{
{ 19, 20}, {21, 22}, {23, 24}
}
};
return 0;
}
I think now I have learned enough to declare and initialize multidimensional array in c languageBut when initializing something like an array, the compiler has to decide whether to interpret the initializer as being for a three-dimensional array in which the innermost dimension happens to have the individual values enclosed with braces, or whether to interpret it as a four dimensional array in which the innermost dimension is a vector of length one. The variable declaration breaks the ambiguity and the compiler is just informing you about which interpretation it chose in case that wasn't the one you meant.
#include<stdio.h>
int main()
{
int array[4][3][2][2] =
{
{
{ {1, 1}, {1, 2}}, {{1,3}, {1,4}}, {{1,5}, {1, 6}}
},
{
{ {1, 7}, {1, 8}}, {{1, 9}, {1, 10}}, {{1, 11}, {1, 12}}
},
{
{ {1, 13}, {1, 14}}, {{1,15}, {1, 16}}, {{1, 17}, {1, 18}}
},
{
{ {1, 19}, {1, 20}}, {{1, 21}, {1, 22}}, {{1, 23}, {1, 24}}
}
};
return 0;
}
Thanks for clearing the doubts. I wrote code with two storage classes and one variable. Experiment show that we cannot have two storages with one variable.At any given point in the code, a given identifier can only refer to one thing, otherwise the compiler may not be able to determine which thing it is referring to when it is used.