Interview Question


Country: United States
Interview Type: Phone Interview




Comment hidden because of low score. Click to expand.
3
of 3 vote

++b - this actually makes it point to the memory location starting at the second row of the original matrix, i.e. {4, 5, 6}
With 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.

- ashot madatyan June 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Nice explanation....
Thnkx...

- chandershekhar2cs June 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

b[1][1] actually replaces 8 of subarray{7,8,9} not 7.

- kuldeep June 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@kuldeep
Yes, that was a nice catch, thanks for that.

- ashot madatyan June 12, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

++b is an error as far as i know .

- Anonymous June 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

The answer is 9.

- Anonymous June 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

++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 June 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is correct, I am agreeing with Thirumal

- sourav June 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@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.

- ashot madatyan June 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

d

- Anonymous June 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Ans . c

- Tripaam June 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we cant increment array names.but when a is passed to function it is no more an array..its just a pointer to an array.and we can increment pointers.
so ++b is a valid statement.
and therefore answer is (b)9..

- garima9792 June 09, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

o/p c) 7

- govind.chauhan143 June 15, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More