Strictly spoken, arrays in high level language are just a method to calculate memory addresses of data objects. If your problem involves multi-dimensional data objects, you'll want the compiler to do the work for you. Otherwise, you may use assembly code as well...What is the reason for having dimensional arrays?
Strictly spoken, arrays in high level language are just a method to calculate memory addresses of data objects. If your problem involves multi-dimensional data objects, you'll want the compiler to do the work for you. Otherwise, you may use assembly code as well...
Value[240,320] = 0xFF ;
The first point is, that you can access the array elements by simply writing indexed expressions, e.g. a[1][0] = 1; In most cases this will be enough and you don't have to care, how the objects are arranged in memory. There is however an implicite order set by the C standard, mapping the array elements to linear addresses:For suppose if i declare my array as a[2][2] instead of a[4]........
how can i access nth element?
int *A_ptr = &A[0][0];
Now you can get the data in memory like A_ptr where it is the ith element in memory after A[0][0];
Code C - [expand] 1 int *A_ptr = &A[0][0];
Code C - [expand] 1 int *A_ptr = &A;
Is it the only way to get the required data by using index...
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 char t1,t2,t3,t4,t5,t6; // six char variables char my_array[2][3]={{'1','2','3'},{'4','5','6'}}; // a two dimensional array char (*my_array_pointer)[3]; // pointer to an array of three char void main(void) { my_array_pointer = my_array; // assign the address to the pointer t1= (*my_array_pointer)[0]; // this is the same as my_array[0][0] t2 = (*my_array_pointer)[1]; // this is the same as my_array[0][1] t3= (*my_array_pointer)[2]; // this is the same as my_array[0][2] my_array_pointer++; // increment pointer t4 = (*my_array_pointer)[0]; // this is the same as my_array[1][0] t5 = (*my_array_pointer)[1]; // this is the same as my_array[1][1] t6 = (*my_array_pointer)[2]; // this is the same as my_array[1][2] }
Or to assign the address of A[0] or A[0][0] or A[0][0][0] you can just write
Code C - [expand] 1 int *A_ptr = &A;
the result is exactly the same
As previously explained, an array is mainly defining a scheme to calculate addresses of memory objects.I might be wong but as far as i know, if it is not dinamically allocated it must be contiguously, but if you alloc an array of pointers they dont need to be contiguously.
I might be wong but as far as i know, if it is not dinamically allocated it must be contiguously, but if you alloc an array of pointers they dont need to be contiguously.
Non-contiguous memory objects have to use other addressing schemes, e.g. liked lists.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?