Filter interviews by
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.
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.
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.
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)
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.
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.
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 differ...
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
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
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.
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 simultane...
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 pr
The 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 i
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.
C 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.
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
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
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
The 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
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...
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.
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
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.
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...
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.
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 a...
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.
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
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
Locks 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...
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 stati...
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, ...
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 ac
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 alloca...
Associative 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 comb...
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 compon...
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 entr...
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))
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
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'...
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.
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 ...
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 ...
The 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
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 popp
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.
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.
Top trending discussions
posted on 8 Mar 2024
I applied via Campus Placement
Test is for 3 hours including coding, mcq and aptitude.
Project Manager
8
salaries
| ₹7.2 L/yr - ₹12.5 L/yr |
Senior Engineer
7
salaries
| ₹3.6 L/yr - ₹6.5 L/yr |
Assistant Engineer
6
salaries
| ₹2.2 L/yr - ₹4 L/yr |
Store Keeper
6
salaries
| ₹2.8 L/yr - ₹3.8 L/yr |
Executive Accountant
6
salaries
| ₹1.8 L/yr - ₹3.6 L/yr |
Prestige Group
DLF
Sobha
Godrej Properties