c Interview Questions | Glassdoor

# c Interview Questions

271

interview questions shared by candidates

## c Interview Questions

Sort: RelevancePopular Date

### R&D Software Engineer at National Instruments was asked...

Apr 7, 2011
 Given a linked list, write a function that will print the list in reverse.2 AnswersDo this in linear O(n) time without recursion and without creating a copy of the list. [Hint] You can modify the list, as long as you put it back the way it started.Traverse the list from start to end updating the link addresses such that the second node points to first, third node points to second and so on. when we reach the last node we will have reverse list. Now repeat the whole process but this time printing the elements of the nodes. We will get the original list back and items printed are in reverse order as well. I am proud of myself !! :)

### Senior Software Engineer at CSR (UK) was asked...

Jan 21, 2012
 Implement int value bit counting.2 Answersfor (i=sizeof(int), t=val; (i>0) && (t==0); t<=1, i--) ;while (n) { n &= n-1; i++; } return i;

### R&D Software Engineer at National Instruments was asked...

Apr 7, 2011
 Given a point a, a distance d, and a large set of points, write a program that efficiently finds all of the points in the set that are less than the distance d from point a. A point consists of an x-coordinate and a y-coordinate.2 AnswersTry to perform calculations only when absolutely necessary. Eliminate as many points as possible without multiplications or square roots.find he equation of a circle with the point a as center and d as radius, now put the given points one by one in the equation to find whether it lies inside or outside.

### Member of Technical Staff IV at Juniper Networks was asked...

Jul 6, 2009
 Given a binary tree, how would you write program for getting mirror image of tree in O(n) time? Is it possible ? Assume you have no constraints on space.2 Answersif t is nul return; Mirror(Right) Mirror(Left) changeNodes(t)//call mirror( root, img_root) //img_node is passed by reference mirror (node, img_node ): if (node == NULL) return img_node.left = node.right img_node.right = mode.left mirror (node.right, img_node.left) mirror (node.left, img_node.right)

### Embedded Software Engineer at iDirect Technologies was asked...

Nov 17, 2010
 2. what is virtual function?2 Answersits base class has a function with keyword virtual and assigned value 0.Virtual function is written with keyword virtual in baseclass and is further overrideden in subclass having same name,return type and signatures..it is basically used to hide base class method from superclass.

### Systems Software Engineer at NVIDIA was asked...

Apr 27, 2012
 Implement memcpy.3 Answersvoid memcpy (int* dest, int* src, int length) { char* currSrc = (char*)src; char* currDest = (char*)dest; for(int i=0; i

### Software Engineer at NVIDIA was asked...

Jan 12, 2011
 Write and aligned malloc() that gets memory size needed and an alignment mask as its arguements. Write a free() function to go with the aligned malloc that takes only the pointer to the allocated chunk of memory.2 AnswersYou basically need to allocated some extra memory with the memory segment that is requested so that you have enough space to align the said chunk and also save a pointer onto the original segment that you get from regular malloc. The free() method via some pointer math will get the "original pointer" and free it.For malloc() you can use the concept of segregated list and do sbrk() to get that much chunk of memory from the kernel. It might lead to some internal fragmentation but thats fine...

### Software Engineer at NVIDIA was asked...

Jan 12, 2011
 Write a macro to which you can pass a name of a structure and a name of one of its fields and get a relative offset of this field within the structure.2 AnswersYou can do this via casting a NULL pointer to the said structure and getting a pointer onto it's field. Won't work on every compiler.s being the struct, f being the field in the struct: #define my_offsetof(s, f) (&(((s *) 0)->f))

### Investment Banking Vice President at Goldman Sachs was asked...

Feb 2, 2012
 If you had 5 red balls that contained 4 red balls and those red balls contained the original 5 red balls, then how many sets of sets of balls would I take to have a double set of red balls of varying sizes inside each next largest red ball?2 Answers15@Interview Candidate: Please give a mathematical breakdown of your answer, as opposed to just expecting us to take your word for it.