Can someone help me with these type of problems | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can someone help me with these type of problems

What is the output of this code? int a[3][4] = {{4,8,13,9},{1,6,9,3}, {0,2,7,10}}; cout << *(*(a+1)+2);

4th Sep 2019, 6:24 PM
Yash Shetty
Yash Shetty - avatar
5 Answers
+ 4
The a is the address of the array, so that is where the first element a[0][0] is found. When we do a+1 we step to the address at the beginning of the next row of the array, the {1,6,9,3} , then the +2 shifts to the right by 2 elements, which is the 9 which is the element at a[1][2]. The * denotes that we want the value stored in that address. I hope that helps.
4th Sep 2019, 11:51 PM
M J
M J - avatar
+ 4
Yash Shetty in 1D array int a[]={1,2,3,4}; a+1 is &a[1] *(a+1) is a[1] 2D array is an 1D array of arrays so in your code *(a+1) will give {1,6,9,3} let b is *(a+1) /*in your mind*/ *(b+2) is the 3rd element of {1,6,9,3} which is 9
5th Sep 2019, 12:02 AM
ABADA S
ABADA S - avatar
+ 3
it is the same with a[1][2] so the answer is 9
4th Sep 2019, 7:13 PM
ABADA S
ABADA S - avatar
0
Sorry but can you please elaborate!
4th Sep 2019, 7:14 PM
Yash Shetty
Yash Shetty - avatar
0
Thanks for the help!
5th Sep 2019, 5:45 AM
Yash Shetty
Yash Shetty - avatar