Re: Link list problem
- From: jdc@xxxxxxxxxxxxxxx (John Cochran)
- Date: Mon, 18 Jul 2005 14:00:00 GMT
In article <1121686911.974617.173390@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Shwetabh <shwetabhgoel@xxxxxxxxx> wrote:
>Hi,
>This is a question asked to me in an interview.
>I haven't been able to figure out an answer for
>it. Please try to see what can be done about the
>following problem.
>
>/* I have been given two structures */
>struct node
>{
> struct node *next;
>} *temp;
>
>struct data
>{
> int a;
> float b;
> char c;
> struct node s;
>};
>
>/* Now the question is to access the values of a,b,c using temp */
>
>Thanks in advance.
>
Ick.
The first thing I'd say is "I hope the code at this company doesn't do
silly things like this."
The second thing is that I'd use the macro "offsetof" along with some creative
casting and pointer arithmetic to transform a "struct node *" into
a "stuct data *". The rest is trivial.
But once again, I'd want an assurance that the above silliness isn't standard
practice at the company you're applying for a job at.
.
- Follow-Ups:
- Re: Link list problem
- From: Netocrat
- Re: Link list problem
- References:
- Link list problem
- From: Shwetabh
- Link list problem
- Prev by Date: Re: manipulating void* in array
- Next by Date: Re: Creative input on indexing from 0 to 99 or 1 to 100
- Previous by thread: Re: Link list problem
- Next by thread: Re: Link list problem
- Index(es):
Relevant Pages
|
|