+ 1
Can someone explain what's happening in printf expression??
8 Respostas
+ 7
(Part 2)
Lets imagine that
variable = *(arr+1);
variable is now equivalent to the {4,5,6} array (in this example)
And accessing the numerical elements will be no different than a regular array.
To get the third element
*(variable+2) == 6
Now replace variable with the original code:
*(*(arr+1)+2)
This is getting the third element of the second array.
and in your code the i and the j are the iterating offsets in a loop
+ 6
(Part 1)
In arrays, using addresses and pointers, elements are accessed by deferencing.
e.g.
int arr[3] = {1,2,3};
printf("%d",*(arr+1));
//This will print the second element, 2. The addend is the address offset of the array. +0 = first element, +1 = second element etc...
Remember that a multidimensional array is an array of arrays, i.e. an array that holds arrays.
Array: {1,2,3}
Array of arrays: {{1,2,3}, {4,5,6}, {7,8,9}};
These individual arrays are accessed the same way as a regular array.
So look at this piece by piece
*(*(arr+i)+j)
*(arr+i)
This piece of code is referring to the elements in the multidimensional array, where the elements are the single dimensional arrays.
When deferencing this, the element we recieve is a single dimensional array
*(arr+1) = {4,5,6}
So this returns a single dimensional array.
So now we've establish that *(arr+1) in this situation is returning a single dimensional array.
+ 1
Thanks for clarification.Nice explanation.
+ 1
Martin Taylor According my professor
"A fool can't think like a computer and solve the code" 😅😅
0
Yeah yeah I know this.But the code was an academical question.As it was the given question I have to sove it.