Aricent Interview Question for Software Engineer / Developers


Country: India
Interview Type: Written Test




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

2

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

The third option in addition to 2 is also right
struct node* m = n;
free( n );
n = m->next;

- Siva Krishna June 28, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

must never free memory before pointing the current node to next (or dereferencing.).

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

can you tell me what is the difference between 2 and 5?

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

Sure. Both 3 and 5 free the memory the pointer points to before attempting to use that memory. Creating a backup of the pointer doesn't help because the backup still points to the same memory location. It's not the pointer that gets altered during a call to free() -- it's the memory it points to. 2 is the correct option, assuming we correct the first line to use a *: struct node* m = n;

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

2

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

And here n should point to start first.

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

also after while loop , *n = NULL else traversal will give runtime error

- vagrawal13 June 27, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

2 if we include *.

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

Actually, trick question. They're all wrong. Option 2 needs a star:

struct node* m = n;
n = n->next;
free( m );

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

Option 3 is also correct if we include *.

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

No, it's not. In 3, you would free the memory pointed to by both n and m before dereferencing it.

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

All are incorrect ....

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

I think they forgot to put the stars on struct node m . 2 was probably the intended answer.

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

chioce 2 is correct.........

- kiran July 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

choice 4 . is correct
because n is a pointer .. first freeing it and then assigning it a new address .. just like we do in deletion of a linked list .
Choice 1 is wrong as it is not saving the next node value .. and choice 2,3,5 are illogical as there is no point in assigning a pointer to a normal struct variable for memory freeing purpose only .

- xenon August 11, 2013 | 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