Marvel Realtors
40+ MapmyIndia Interview Questions and Answers
Q1. 2 queues q1 and q2 are given.A background process copies elements from q1 to q2.In case an error occurs elements from q2 need to be copied back again to q1.Write this error handling function using foll function...
read moreThe error handling function copies elements from q2 back to q1 in case of an error.
Use q_len() to get the length of the queues
Use q_insert() and q_remove() to manipulate the queues
Iterate through q2 and use q_insert() to copy elements back to q1
Q2. there are 2 processors each executing a separate program- processor 1 int a=10 int *ptr = &a; ptr is written into file1 processor sleeps for 10sec printf("%d",a); processor 2 int *p; file1 is read and contents ...
read moreThe output will be 5.
Processor 1 initializes variable 'a' with a value of 10 and creates a pointer 'ptr' pointing to 'a'.
Processor 1 writes the value of 'ptr' into 'file1' and then sleeps for 10 seconds.
Processor 2 reads the contents of 'file1' and saves it in pointer 'p'.
Processor 2 assigns the value 5 to the memory location pointed by 'p'.
When Processor 1 wakes up and executes the printf statement, it will print the updated value of 'a', which is 5.
Q3. Write a C code to delete a node from circular doubly linked list where you cannot delete the head node.. (At the last i was very eager to know the answers to the questions he asked me, But he refused to answer ...
read moreC code to delete a node from circular doubly linked list without deleting the head node.
Start from the head node and traverse the list until the desired node is found.
Update the next and previous pointers of the adjacent nodes to skip the node to be deleted.
Free the memory allocated for the node to be deleted.
Q4. Process p1 & p2. p1 writes to an address & sleeps...p2 writes another value to the same address & terminates. Now p1 wakes up & reads value of that address. He asked me the output.What is Role of OS in this...
read moreThe output of p1 depends on the synchronization mechanism used by the operating system.
If the OS uses a lock or semaphore to synchronize access to the shared address, p1 will read the value written by p2.
If the OS does not provide any synchronization mechanism, the output of p1 is unpredictable and may vary.
The role of the OS is to manage the execution of processes, provide synchronization mechanisms, and ensure data integrity.
Q5. What is associative mapping ? What is difference between associative mapping and direct mapping ? What is set associative mapping? (After hearing last question I cursed myself for not reading AMP book for MST.....
read moreAssociative mapping is a cache mapping technique where a memory block can be placed in any cache location. Direct mapping is a technique where each memory block is mapped to a specific cache location. Set associative mapping is a combination of both.
Associative mapping allows flexibility in placing memory blocks in cache.
Direct mapping assigns a specific cache location for each memory block.
Set associative mapping combines the flexibility of associative mapping with the struc...read more
Q6. What are locks? If you have non pre-emptive uni processor system, is there any need of lock. (He himself was confused about what he was asking & my questions made him more confused, So in end he said lets leave...
read moreLocks are synchronization mechanisms used to control access to shared resources in multi-threaded environments.
Locks prevent multiple threads from accessing shared resources simultaneously.
They ensure that only one thread can access a shared resource at a time.
Locks help in preventing race conditions and maintaining data integrity.
They can be implemented using various techniques such as mutexes, semaphores, or monitors.
In a non pre-emptive uni processor system, where only one...read more
Q7. What is the role of virtual memory if there is no swap space...(Interviewer was So knowledgeable about memory management that We spent 1 hour out of 1.45 hour on discussing virtual memory only.. :-o )
Virtual memory allows the operating system to use disk space as an extension of RAM when there is no swap space.
Virtual memory allows programs to use more memory than physically available.
It provides a way to manage memory efficiently by swapping data between RAM and disk.
Without swap space, virtual memory cannot be used effectively.
Virtual memory helps in running large programs and multitasking.
It allows for memory protection and isolation between processes.
Q8. Write a code to delete a node from singly linked list where you will be given head and offset of the node to be deleted
Code to delete a node from a singly linked list given the head and offset of the node.
Traverse the linked list until the node at the given offset is reached.
Update the next pointer of the previous node to skip the node to be deleted.
Free the memory occupied by the node to be deleted.
Q9. a function returns a float ,the float value may also indicate error/failure in the function.How will u implement it?
To indicate error/failure in a function that returns a float, use a special value or an additional parameter.
Use a special value like NaN or a negative value to indicate error/failure.
Alternatively, add an additional parameter to the function to return an error code or message.
Handle the error/failure condition appropriately in the calling code.
Q10. what is binary search tree...given n elements in binary tree....what is max ht of tree...what is search complexity for the case when this ht is max....how can u reduce it?
A binary search tree is a data structure where each node has at most two children, and the left child is smaller than the parent while the right child is larger.
The maximum height of a binary search tree with n elements is n-1.
The search complexity for the case when the height is maximum is O(n).
To reduce the search complexity, we can balance the binary search tree using techniques like AVL trees or Red-Black trees.
Q11. What is virtual memory ? Why is it called virtual ? Whats the area of hard disk where pages are replaced to, called?
Virtual memory is a memory management technique that allows the operating system to use a combination of RAM and hard disk space.
Virtual memory is a way for the operating system to provide more memory to applications than what is physically available in RAM.
It creates an illusion of a larger memory space by using a portion of the hard disk as an extension of RAM.
Virtual memory allows multiple processes to run simultaneously without the need for physical memory to accommodate ...read more
Q12. wht ll be the size of struct abc{ int a; char b; short c;}; ? how will they be arranged when they are allocated memory?
The size of struct abc will be 8 bytes. The members will be arranged in the order of declaration.
The struct abc has three members: int a, char b, and short c.
The size of int is typically 4 bytes, char is 1 byte, and short is 2 bytes.
The total size of the struct is the sum of the sizes of its members, which is 4 + 1 + 2 = 7 bytes.
However, due to memory alignment and padding, the size of the struct will be rounded up to the nearest multiple of the largest member's size, which i...read more
Q13. What determines the padding size for the last member of the struct ? (We discussed this for half an hour probably !!)
The padding size for the last member of a struct is determined by the alignment requirements of the struct.
Padding is added to ensure that each member of the struct is properly aligned in memory.
The padding size depends on the size and alignment requirements of the previous members.
The compiler may also consider the target architecture and optimization settings when determining padding size.
Q14. struct abc{ int a; int b; char c;}; wht is the size of the structure? how will the members be allocated memory?
The size of the structure is 12 bytes. The members will be allocated memory based on their data types.
The structure 'abc' has three members: 'a' of type int, 'b' of type int, and 'c' of type char.
The size of int is typically 4 bytes and the size of char is typically 1 byte.
The total size of the structure is calculated by summing the sizes of its members.
In this case, 4 bytes for 'a', 4 bytes for 'b', and 1 byte for 'c', resulting in a total of 12 bytes.
The members will be all...read more
Q15. Represent numbers using linked list. How would you add two numbers represented in linked list form. Length of numbers can be different
Adding two numbers represented as linked lists with different lengths.
Traverse both linked lists simultaneously, adding corresponding digits and carrying over the carry.
If one list is shorter, consider the remaining digits as 0.
Create a new linked list to store the result.
Handle the case when the sum of digits exceeds 9 by carrying over the digit to the next place value.
If there is a carry after adding all digits, add an additional node to the result linked list.
Q16. how static and global variables work- when they are declared inside and when they are declared outside the functions
Static and global variables have different scopes and lifetimes depending on where they are declared.
Static variables declared inside a function retain their value between function calls.
Static variables declared outside any function have file scope and are accessible within the file.
Global variables have global scope and can be accessed from any part of the program.
Global variables are initialized only once and retain their value throughout the program execution.
Q17. -a try block throws an exception which is caught by catch()...how the throw() is internally implemented
The throw() statement is internally implemented by creating an exception object and transferring control to the catch() block.
When a throw() statement is executed, an exception object is created.
The exception object contains information about the type of exception and any additional data.
The control is then transferred to the nearest catch() block that can handle the exception.
The catch() block can access the exception object and perform appropriate actions.
If no catch() bloc...read more
Q18. synchronisation and locks - given 2 threads...print out 1 to 10 such that 1 thread shud print all odd nos and other should print even nos
The question is about synchronizing two threads to print odd and even numbers from 1 to 10.
Use synchronization mechanisms like locks or semaphores to ensure only one thread prints at a time
Create two separate functions for printing odd and even numbers
Use a shared variable to keep track of the current number being printed
Use a loop to iterate from 1 to 10 and call the appropriate function based on the current number
Q19. how ll u implement a queue using a stack, u can use only push n pop
A queue can be implemented using a stack by using two stacks and simulating the enqueue and dequeue operations.
Create two stacks, stack1 and stack2.
For enqueue operation, push the element onto stack1.
For dequeue operation, if stack2 is empty, pop all elements from stack1 and push them onto stack2. Then pop the top element from stack2.
This ensures that the first element pushed onto stack1 is the first element to be popped from stack2, simulating a queue.
Q20. Can you assign variable value to a static variable during initialization ?
Yes, a variable value can be assigned to a static variable during initialization.
Static variables are initialized only once, at the start of the program.
The value assigned to a static variable during initialization can be a constant or the result of an expression.
The assigned value can be changed later in the program, but it will retain its value between function calls.
Static variables are useful for preserving data across multiple function calls.
Q21. Can paging be implemented completely in OS, thus, removing paging hardware?
No, paging cannot be implemented completely in the OS without paging hardware.
Paging is a hardware feature that allows the operating system to manage memory efficiently.
Without paging hardware, the OS would not have the necessary mechanisms to map virtual addresses to physical addresses.
Paging hardware includes components like the Memory Management Unit (MMU) and Translation Lookaside Buffer (TLB).
These hardware components are responsible for translating virtual addresses to ...read more
Q22. Where are static global variables stored. Where are function’s static variable stored ?
Static global variables are stored in the data segment of the program's memory. Function's static variables are also stored in the data segment.
Static global variables are allocated memory when the program starts and retain their values throughout the program's execution.
Function's static variables are local to the function but retain their values between function calls.
Both static global variables and function's static variables have a lifetime that extends for the entire du...read more
Q23. Why the value of static variable initialised to Zero ? Why not any other constant ?
Static variables are initialized to zero because it is a default value that ensures predictable behavior and avoids potential bugs.
Initializing static variables to zero provides a known starting point for calculations or comparisons.
Zero is a neutral value that does not affect the outcome of most operations.
Using a constant other than zero could introduce unexpected behavior or require additional handling.
For example, if a static variable is initialized to a non-zero constant...read more
Q24. why is this padding done? how is it decided how much padding should be done and where?
Padding is done to add extra space or characters to a data structure or field for various reasons.
Padding is done to align data structures in memory or disk storage.
It can be used to ensure proper memory alignment for efficient access and performance.
Padding can also be used for data integrity and security purposes.
The amount of padding and its placement is determined by the specific requirements of the data structure or protocol being used.
For example, in networking protocol...read more
Q25. if i change it to struct abc{ int a; char c; int b;}; will size change?
Yes, the size will change.
The size of the struct will change because the order of the members has changed.
The size of the struct will depend on the size of its members and any padding added by the compiler.
In this case, the size of the struct will likely increase due to the addition of the 'char c' member.
Q26. Reverse a doubly linked list(only head pointer is given) (Both recursive and non-recursive methods) //this Q was asked to almost 10-12 students ;)
Reverse a doubly linked list using both recursive and non-recursive methods.
Start with the head pointer and initialize two pointers, prev and next.
For the non-recursive method, iterate through the list and update the prev and next pointers.
For the recursive method, recursively call the reverse function on the next node and update the pointers.
Remember to update the head pointer at the end.
Q27. int a[10] printf(“%d”,sizeof(a)) what will be the output?
The output will be the size of the array in bytes, which is 40.
The 'sizeof' operator returns the size of a variable or data type in bytes.
In this case, 'sizeof(a)' will return the size of the array 'a' in bytes.
Since 'a' is an array of 10 integers, each taking 4 bytes, the total size will be 10 * 4 = 40 bytes.
Q28. why cant u open two serial port connections at a time
Opening two serial port connections at a time is not possible due to hardware limitations.
Serial ports are physical interfaces that allow communication between a computer and external devices.
Each serial port has a unique identifier and can only be accessed by one application at a time.
Attempting to open two serial port connections simultaneously would result in conflicts and errors.
To overcome this limitation, you can use multiplexing techniques or virtual serial ports.
Q29. how ll u find out if there is a loop in a link list
To find a loop in a linked list, we can use the Floyd's cycle-finding algorithm.
Initialize two pointers, slow and fast, both pointing to the head of the linked list.
Move slow pointer by one step and fast pointer by two steps.
If there is a loop, the slow and fast pointers will eventually meet at the same node.
If the fast pointer reaches the end of the list (null), there is no loop.
Q30. Whats the maximum memory you can allocate with malloc()
The maximum memory that can be allocated with malloc() depends on the system's available memory and the size of the largest contiguous block of memory.
The maximum memory that can be allocated is limited by the system's available memory.
The size of the largest contiguous block of memory also affects the maximum memory that can be allocated.
malloc() returns a null pointer if the requested memory cannot be allocated.
Q31. write a function to check whether a substring is present in the string
A function to check whether a substring is present in a string.
Use the built-in string method 'includes()' to check if the substring is present in the string.
Return true if the substring is found, otherwise return false.
Q32. Can pointers be added,subtracted etc
Yes, pointers can be added, subtracted, and manipulated in various ways.
Pointers can be incremented or decremented to access different memory locations.
Pointer arithmetic can be used to iterate over arrays or manipulate data structures.
Adding or subtracting an integer to a pointer moves it by that many elements in the array.
Q33. Array of pointers,pointer to arrays and their byte sizes
Explanation of array of pointers, pointer to arrays, and their byte sizes.
Array of pointers: An array where each element is a pointer to another data type.
Pointer to arrays: A pointer that points to the first element of an array.
Byte sizes: The amount of memory occupied by each of these constructs.
Q34. Write a macro To add/multiply two numbers and some variations
A macro to add/multiply two numbers
Use the preprocessor directive #define to define the macro
For addition, use the + operator and for multiplication, use the * operator
Enclose the macro in parentheses to ensure correct evaluation of expressions
Example: #define ADD(x, y) ((x) + (y))
Example: #define MULTIPLY(x, y) ((x) * (y))
Q35. towers of hanoi- explain algorithm and write code [recursive]
The Towers of Hanoi is a mathematical puzzle that involves moving a stack of disks from one peg to another using recursion.
The algorithm follows a recursive approach.
It involves moving n-1 disks from the source peg to the auxiliary peg.
Then, move the largest disk from the source peg to the destination peg.
Finally, move the n-1 disks from the auxiliary peg to the destination peg.
Repeat the above steps recursively for the remaining disks.
Q36. how are static functions used in c/c++
Static functions in C/C++ are functions that can only be accessed within the same file they are defined in.
Static functions are declared using the 'static' keyword.
They cannot be called using an object or instance of a class.
They are useful for encapsulating functionality that is only relevant within a specific file.
Static functions can access only static variables and other static functions within the same file.
They are not part of the class's interface and cannot be overrid...read more
Q37. What are Tries and why they are used
Tries are tree-like data structures used for efficient retrieval of strings, commonly used in autocomplete and spell checking.
Tries are used to store and search for strings efficiently
Each node in a trie represents a character, forming a tree-like structure
Tries are commonly used in autocomplete and spell checking applications
They allow for fast prefix matching and searching for words
Q38. macro to set a particular bit of a number
A macro to set a particular bit of a number.
Use bitwise OR operator to set the bit at the desired position.
Shift 1 to the left by the desired position to create a mask.
Perform bitwise OR operation between the number and the mask to set the bit.
Q39. int *p[5]; int (*q)[5]; sizeof(p)=? sizeof(q)=?
The sizeof(p) will return the size of the array of pointers, while sizeof(q) will return the size of a pointer to an array.
sizeof(p) will be equal to 5 times the size of a pointer
sizeof(q) will be equal to the size of a pointer
Q40. Identify a system as big or little endian
Big endian is a system where the most significant byte is stored first, while little endian is the opposite.
Big endian: MSB first (e.g. 0x1234 is stored as 12 34)
Little endian: LSB first (e.g. 0x1234 is stored as 34 12)
Q41. write code to reverse a doubly linked list
Code to reverse a doubly linked list
Start from the head of the linked list
Swap the prev and next pointers of each node
Update the head and tail pointers accordingly
Q42. what is paging,segmentation
Paging is a memory management technique that allows the operating system to store and retrieve data from secondary storage.
Paging divides the memory into fixed-size blocks called pages.
It allows for efficient memory allocation and management.
Each page is mapped to a frame in physical memory.
Segmentation is another memory management technique that divides the memory into variable-sized segments.
Segments can be of different lengths and are used to store different types of data....read more
Q43. -find if a linkedlist is circular
Check if a linked list is circular by using two pointers.
Initialize two pointers, slow and fast, both pointing to the head of the linked list.
Move slow pointer by one node and fast pointer by two nodes at a time.
If the linked list is circular, the fast pointer will eventually catch up with the slow pointer.
If the fast pointer reaches the end of the list (null), the linked list is not circular.
Q44. Write all possible test cases for adder
Test cases for adder function
Test with positive numbers
Test with negative numbers
Test with zero
Test with large numbers
Test with decimal numbers
Test with different data types
Q45. What is TLB ?
TLB stands for Translation Lookaside Buffer. It is a hardware cache that stores recently accessed virtual-to-physical memory translations.
TLB is a cache used in computer processors to improve memory access times.
It stores recently accessed virtual-to-physical memory translations.
TLB reduces the need to access the slower main memory for translation lookups.
TLB is an important component in virtual memory systems.
TLB entries can be invalidated or flushed when the page tables are...read more
Q46. What is paging ?
Paging is a memory management technique used in operating systems to efficiently manage memory resources.
Paging divides the physical memory into fixed-size blocks called pages.
Virtual memory is divided into fixed-size blocks called page frames.
When a process needs to access a memory location, the operating system maps the virtual address to a physical address using a page table.
Paging allows for efficient memory allocation and sharing among multiple processes.
Examples of pagi...read more
Q47. Program Logic to solve Sudoku
Program logic to solve Sudoku
Implement a backtracking algorithm
Start with an empty grid
Iterate through each cell and try different numbers
If a number is valid, move to the next cell
If no valid number is found, backtrack to the previous cell
Repeat until the grid is filled or no solution is possible
Q48. reverse a singly link list
Reverse a singly linked list
Iteratively swap the next and previous pointers of each node
Use three pointers to keep track of the current, previous, and next nodes
Update the head pointer to the last node after reversing
Top Software Engineer Interview Questions from Similar Companies
Reviews
Interviews
Salaries
Users/Month