Interview Question
Country: United States
Interview Type: Phone Interview
++b is an error because. we can't increment the array name. which is internally constant pointer.
if its a pointer the the answer is 9
@Thirumal.
U are not actually incrementing the array name (b) because in the function " void foo( int b[][3]) " you will actually be passed a copy of the pointer pointing to the original array. So, incementing this pointer does not actually change the array's location - instead, the copy of the pointer is changed by the ++b operator.
++b - this actually makes it point to the memory location starting at the second row of the original matrix, i.e. {4, 5, 6}
- ashot madatyan June 06, 2012With the new pointer and using the [1][1] dimensions we will be addressing (accessing) the memory location [2][1] in the original matrix, i.e. element with value 7 in the row {7,8,9}.
So, after the call to foo function we have a modified matrix { 1,2,3} , { 4,5,6},{9,8,9}, and the call to "printf("%d" , a[2][1]);" will actually print 9.
So , the correct answer is B.