+ 1

Explain me this output

Int arr[2][3] = {2,3,4,5,6,7}; Printf("%d",(*(*arr+1))));

19th Mar 2020, 10:32 AM
Gaurav Rawat
Gaurav Rawat - avatar
3 Answers
+ 3
The output should be a compiler error. There are too many closing parentheses on the printf statement. Also int and printf should not be capitalized, but I assume your keyboard added capitalization. Here is the corrected code. I added braces to clarify the row groupings: int arr[2][3] = {{2,3,4},{5,6,7}}; printf("%d",(*(*arr+1))); Since arr is a two-dimensional array, think of it as a pointer to row pointers. To reach the value of an element, it requires two dereferences. Here is how it occurs above: *arr is a pointer to the first row {2,3,4} (*arr)+1 shifts the row pointer to the second element of the row *((*arr)+1) returns the contents, 3 I added parentheses to clarify the order of operations. It is the same as *(*arr+1).
19th Mar 2020, 12:27 PM
Brian
Brian - avatar
+ 2
Output is 3. Poienter *arr indicate arr [0]=2; *arr+1 indicate arr [1]=3. Same thing do the *(*arr+1)
19th Mar 2020, 12:14 PM
Sohanur Rahman
Sohanur Rahman - avatar
0
your code indicating error. because acc to statement shows two dimensional array arr[2][3] two rows and three column but arr[2][3] = {{2,3,4},{5,6,7}}; you code should be this.
20th Mar 2020, 4:07 PM
Abhishek Singh
Abhishek Singh - avatar