Interview Question


Country: United States




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

2-D arrays allocated on the stack are actually allocated as a contiguous 1-D array. When you pass this to a method, methods have no idea what something like array[X][Y] refers to because it needs to refer to array[X*ySize+Y], but the called method has no size information. In my opinion, this is a very unfortunate feature of C. 1-D arrays shouldn't be masquerading as 2-D arrays.

- eugene.yarovoi June 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

in f we can change as
int c[2][2] as well

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

error in code
type mismatch . from calling to receiving .
in f change
int (*c)[2]
output : 1

- Nitin Gupta iitian June 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess you might get that too, because the array in the caller method is only pretending to be a 2-D array when it's a 1-D array.

- eugene.yarovoi June 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry ...i can't understand what you wana say...?

- Nitin Gupta iitian June 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I'm saying that the declaration int c[2][2]={1,2,3,4}; makes a 1-D array and not an array of arrays (2-D array). One of the things I think is so very wrong with C and C++

- eugene.yarovoi June 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Let me describe you why?
int c[2][2] ; is actually like that int (*c)[2] and c = new int [2][2];
but int **c ; is different from that .....
that's y
in case of 1D array
int c[2] ; its actually like that int *c = new int [2] ; which is similir with int *c ;
i have use dynamic array for clarifying my point only

- Nitin Gupta iitian June 29, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@eugene.yarovoi
i got it .....yes it seems

- Nitin Gupta iitian June 29, 2012 | Flag


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