Interview Question


Country: United States




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

extern is used outside.It should be used inside code.

- vineetsetia009 May 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

When both file links during execution extern int *myarray declaration in file2.c will search for *myarray declared and allocated space ,and that is done in file1.c myarray[10].So what exactly you are saying is *myarray will not match to myarray[].

- anuj.iiit2007 May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

c-faq.com/decl/extarraysize.html

- anon.coder May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Also in file2.c, we should use
extern int myarray[];
and not
extern int *myarray;
since the latter will give error - error: conflicting types for ‘myarray'

- anon.coder May 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

instead of extern int *myarray, extern int myarray[10] should be used and in file 2 we have to include file1 as header .which can be done by including #include at the front of source file i.e file 2 in this case.

- dekontj May 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

after running i got
"error: conflicting types for ‘myarray’"

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

after running with gcc compiler,i got
"error: conflicting types for ‘myarray’"

- Anonymous August 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

arrays are special types which represents a continuous storage location . here you are making a pointer to an array , which would actually concider the first element i.e myarray [0] as its value
. when you deference *myarray it actually goes to the "myarray[0]" address which may be valid or invalid ..
i think linker should have complained i dont know ..
the confusion occurs because these statement works perfectly
int array[10];
int *ptr = array ;
ptr[0] = 10 ;

- tigerthepuli May 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 3 vote

The code may give segmentation fault or linking error.

int array[10]; tells that array is an array of 10 integers.
extern int*myarray; tells that myarray is a pointer to an integer which in defined at some other, place probably in some other .c file. But it is not defined any where(even not initiallised).

- Learn Android: http://learnandroideasily.blogspot.in/ May 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

When both file links during execution extern int *myarray declaration in file2.c will search for *myarray declared and allocated space ,and that is done in file1.c myarray[10].So what exactly you are saying is *myarray will not match to myarray[].

- anuj.iiit2007 May 13, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

after running i got
"error: conflicting types for ‘myarray’"

- Anonymous August 27, 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