Interview Question


Country: United States


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

struct A
{
    int a;
    char c;
};

A doSomething()
{
   A x;

   return (x);
}

- Anonymous on July 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

x is on stack. You won't be able to access on return. Allocating on heap and then returning the pointer can be one way.

- neer300 on July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Though x is on stack we are sending content not address of x.. So no problem..

- Chandu on July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Structs are passed by value. There is no problem here.

- eugene.yarovoi on July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

my bad

- neer300 on July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int func(char * c, int a){
c=....; /* pointer to the char so changes will b reflected*/
a=....;
return (a);
}

- Anuda on July 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

You would need to use *c on the left side of the assignment, then

- eugene.yarovoi on July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

ya ryt..missed dat

- Anuda on July 16, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

It's better to use the pointer as the parameter of the function.e.g void foo(int * re1,char *re2,...)

- notbad on July 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

main()
{
struct A
{
int a;
char c;
}
dosomething();

struct A dosomething()
{
struct A x={ 5,"a"};
return x;
}
}

- sivatejakambham on August 17, 2012 | Flag Reply


Add a Comment
Name:

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

Books

is a comprehensive book walking you through 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