Can someone explain what's happening in printf expression?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone explain what's happening in printf expression??

https://code.sololearn.com/ck69IP47w8p8/?ref=app

24th Jun 2021, 4:45 PM
Vatsav
6 Answers
+ 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
24th Jun 2021, 6:04 PM
Odyel
Odyel - avatar
+ 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.
24th Jun 2021, 6:04 PM
Odyel
Odyel - avatar
+ 1
Thanks for clarification.Nice explanation.
24th Jun 2021, 11:49 PM
Vatsav
+ 1
Martin Taylor According my professor "A fool can't think like a computer and solve the code" 😅😅
25th Jun 2021, 12:13 AM
Vatsav
0
Yeah yeah I know this.But the code was an academical question.As it was the given question I have to sove it.
25th Jun 2021, 12:07 AM
Vatsav
25th Jun 2021, 12:08 AM
Vatsav