C Developer
60+ C Developer Interview Questions and Answers
Popular Companies
Q1. String Transformation Problem
Given a string (STR
) of length N
, you are tasked to create a new string through the following method:
Select the smallest character from the first K
characters of STR
, remove it fr...read more
Given a string and an integer, create a new string by selecting the smallest character from the first K characters of the input string and repeating the process until the input string is empty.
Iterate through the input string, selecting the smallest character from the first K characters each time.
Remove the selected character from the input string and append it to the new string.
Continue this process until the input string is empty.
Return the final new string formed.
Q2. Merge K Sorted Arrays Problem Statement
Given 'K' different arrays that are individually sorted in ascending order, merge all these arrays into a single array that is also sorted in ascending order.
Input
The f...read more
Merge K sorted arrays into a single sorted array.
Create a min heap to store the first element of each array along with the array index.
Pop the top element from the heap, add it to the result array, and push the next element from the same array back to the heap.
Continue this process until all elements are processed.
Time complexity can be optimized using a priority queue or merge sort technique.
C Developer Interview Questions and Answers for Freshers
Q3. Sort 0 1 2 Problem Statement
Given an integer array arr
of size 'N' containing only 0s, 1s, and 2s, write an algorithm to sort the array.
Input:
The first line contains an integer 'T' representing the number of...read more
Sort an array of 0s, 1s, and 2s in linear time complexity.
Use three pointers to keep track of 0s, 1s, and 2s while iterating through the array.
Swap elements based on the values encountered to sort the array in-place.
Ensure to handle edge cases like all 0s, all 1s, and all 2s in the array.
Q4. Find Maximum Number by At-most K Swaps
Given an array of non-negative integers representing the digits of a number and an integer 'K', calculate the maximum possible number by swapping its digits up to 'K' time...read more
Given an array of digits and an integer K, find the maximum number by swapping digits up to K times.
Sort the digits in non-increasing order to maximize the number.
Swap the digits to achieve the maximum number within the given number of swaps.
Handle cases where there are repeating digits and leading zeros.
Q5. BST Node Deletion Problem
Given a binary search tree (BST) and a key value K
, your task is to delete the node with value K
. It is guaranteed that a node with value K
exists in the BST.
Explanation:
A binary sea...read more
Delete a node with a given value from a binary search tree (BST).
Traverse the BST to find the node with the value K to be deleted.
Handle different cases like node with no children, one child, or two children.
Update the pointers of the parent node and child nodes accordingly.
Recursively delete the node and adjust the tree structure.
Return the root of the modified BST after deletion.
Q6. Move Zeroes to End Problem Statement
Given an unsorted array of integers, modify the array such that all the zeroes are moved to the end, while maintaining the order of non-zero elements as they appear original...read more
Move all zeroes to the end of an unsorted array while maintaining the order of non-zero elements.
Iterate through the array and keep track of the index to place non-zero elements.
Once all non-zero elements are placed, fill the rest of the array with zeroes.
Ensure to maintain the relative order of non-zero elements.
Example: Input: [0, 1, -2, 3, 4, 0, 5, -27, 9, 0], Output: [1, -2, 3, 4, 5, -27, 9, 0, 0, 0]
Share interview questions and help millions of jobseekers 🌟
Q7. Preorder Traversal of a BST Problem Statement
Given an array PREORDER
representing the preorder traversal of a Binary Search Tree (BST) with N
nodes, construct the original BST.
Each element in the given array ...read more
Given a preorder traversal of a BST, construct the BST and return its inorder traversal.
Create a binary search tree from the preorder traversal array
Return the inorder traversal of the constructed BST
Ensure each element in the array is distinct
Structures in C++ allow for multiple data types to be grouped together, while unions share the same memory space for all members.
Structures in C++ can hold multiple data types, each with its own memory allocation.
Unions in C++ share the same memory space for all members, allowing only one member to be active at a time.
Structures are used when different types of data need to be stored together, while unions are used when only one type of data needs to be stored at a time.
C Developer Jobs
Q9. what are processes and threads memory is allocated to what process or threads? what is mutex and semaphore how many threads/process can you launch at a time what is meaning of core in 4-core system what is cont...
read moreProcesses and threads are units of execution in a computer system. Memory is allocated to processes. Mutex and semaphore are synchronization mechanisms. Core refers to a processing unit in a multi-core system. Context switching is the process of switching between different processes or threads.
Processes are independent units of execution with their own memory space and resources.
Threads are lightweight units of execution within a process, sharing the same memory space.
Memory ...read more
Dynamic memory allocation in C allows for allocating memory at runtime, enabling flexibility in memory usage.
Dynamic memory allocation is done using functions like malloc(), calloc(), realloc() in C.
It allows for allocating memory as needed during program execution.
Dynamic memory allocation helps in managing memory efficiently by allocating and deallocating memory as required.
Example: int *ptr = (int*)malloc(5 * sizeof(int)); // Allocates memory for an array of 5 integers
To convert a value from Big Endian to Little Endian format, reverse the order of bytes.
Iterate through the bytes of the value in reverse order
Swap the positions of each byte to convert from Big Endian to Little Endian
Example: Big Endian value 0x12345678 becomes Little Endian value 0x78563412
Q12. Const pointer and pointer to const Join in Multithreading
Const pointer and pointer to const in multithreading
A const pointer cannot change the memory address it points to, but can change the value at that address
A pointer to const can change the memory address it points to, but cannot change the value at that address
In multithreading, const pointers can be used to ensure thread safety by preventing multiple threads from modifying the same memory location
Q13. Constants in C, Classes and object oriented programing system concepts in c++
Constants in C and OOP concepts in C++
Constants in C are variables whose value cannot be changed during program execution
Classes in C++ are user-defined data types that encapsulate data and functions
Object-oriented programming in C++ involves the use of classes, objects, inheritance, and polymorphism
Q14. Time complexity of any sorting algorithm. Types of trees and linked list. How to achieve the concept of linked list in c++?
Sorting algorithm time complexity, types of trees and linked list, and implementing linked list in C++.
Sorting algorithms have different time complexities, such as O(n^2) for bubble sort and O(n log n) for quicksort.
Trees include binary, AVL, and red-black trees, among others.
Linked lists are a data structure where each element points to the next one, such as singly and doubly linked lists.
In C++, linked lists can be implemented using pointers and dynamic memory allocation.
Q15. What is class and objects in c++?
Class is a blueprint for creating objects. Objects are instances of a class with their own set of properties and methods.
Classes define the properties and methods that objects will have
Objects are created from a class using the 'new' keyword
Objects can interact with each other through their methods and properties
Example: class Car { int speed; void accelerate(); }; Car myCar; myCar.accelerate();
Example: class Person { string name; int age; void sayHello(); }; Person john; joh...read more
Q16. Why we use join in Multithreading
Join is used to wait for a thread to finish execution before continuing with the main thread.
Join ensures that all the threads finish their execution before the main thread exits.
It is used to avoid race conditions and deadlocks.
Join can be used with detach to ensure that the thread is not left running in the background.
Example: Joining a thread that performs a time-consuming task before continuing with the main thread.
Example: Joining multiple threads to ensure that all the ...read more
Q17. How to create thread, what is POSIX library? How many parameters we pass while creating thread.
Creating threads using POSIX library and passing parameters.
POSIX library provides functions for creating and managing threads in C++.
To create a thread, we use the pthread_create() function.
The function takes four parameters: a pointer to a pthread_t object, thread attributes, a function pointer to the thread function, and a void pointer to the thread function's argument.
Example: pthread_t thread; pthread_create(&thread, NULL, myThreadFunction, (void*)myArgument);
Q18. Scope of logic for functions, if blocks, loops, case structures.
Functions, if blocks, loops, and case structures have a wide scope of logic in C development.
Functions allow for modular and reusable code.
If blocks provide conditional logic.
Loops allow for repetitive tasks.
Case structures provide a way to handle multiple conditions.
All of these structures can be combined to create complex logic.
Proper use of these structures can improve code readability and maintainability.
Q19. Singleton class creation (code) what is use of it ?
Singleton class ensures only one instance of a class is created and provides a global point of access to it.
Ensures only one instance of a class is created
Provides a global point of access to the instance
Useful for managing global resources or settings
Q20. Object oriented programming in c++
Object-oriented programming in C++ is a programming paradigm that uses objects to represent real-world entities.
Encapsulation, inheritance, and polymorphism are the three main pillars of OOP in C++.
Classes and objects are the building blocks of OOP in C++.
OOP in C++ allows for code reusability, modularity, and easier maintenance.
Example: A car can be represented as an object in C++ with properties like make, model, and color, and methods like start and stop.
Example: Inheritan...read more
Q21. How do you improve the code quality in the given piece of C++ code?
To improve code quality in C++ code, focus on readability, maintainability, performance, and adherence to best practices.
Use meaningful variable and function names to improve readability.
Break down complex functions into smaller, more manageable functions.
Follow coding standards and best practices such as using const-correctness, avoiding magic numbers, and using appropriate data structures.
Use comments and documentation to explain the purpose and functionality of the code.
Pe...read more
Q22. Runtime polymorphism and how it works vptr and vtable
Runtime polymorphism in C++ is achieved through virtual functions, vptr (virtual pointer), and vtable (virtual table).
Runtime polymorphism allows objects of different classes to be treated as objects of a common superclass.
Virtual functions are declared in a base class and overridden in derived classes to achieve polymorphism.
vptr is a pointer that points to the vtable of an object, allowing dynamic binding of virtual functions at runtime.
vtable is a table of function pointer...read more
A zombie process is a process that has completed execution but still has an entry in the process table.
Zombie processes occur when a child process finishes execution before the parent process can collect its exit status.
Zombie processes consume system resources and should be cleaned up by the parent process using wait() or waitpid() system calls.
Zombie processes can be identified using tools like ps command in Unix/Linux systems.
Example: When a parent process forks a child pr...read more
Q24. Arrays in C, Public and private variables
Arrays in C are used to store multiple values of the same data type. Public and private variables are used for data encapsulation.
Arrays can be declared using square brackets, e.g. int arr[5];
Public variables can be accessed and modified by any part of the program, while private variables can only be accessed and modified within the same class or function.
Arrays of strings can be declared using char arr[5][10]; where 5 is the number of strings and 10 is the maximum length of ...read more
Q25. what is dynamic_cast where it can fail and what will happen in that case
dynamic_cast is a C++ operator used for safe downcasting of pointers and references in polymorphic classes.
dynamic_cast is used to safely downcast a pointer or reference from a base class to a derived class.
It can fail if the object being casted is not of the target type, in which case it returns a null pointer for pointers or throws a std::bad_cast exception for references.
Dynamic_cast can only be used with pointers or references to polymorphic classes (classes that have at ...read more
Q26. 3. Write a class to debit, credit and balance check functionalities
A class for debit, credit and balance check functionalities
Create a class with member variables for balance
Add member functions for debit, credit and balance check
Ensure proper validation and error handling
Consider using exception handling for errors
Q27. Memory management of variable and objects
Memory management involves allocating and deallocating memory for variables and objects.
Variables can be allocated on the stack or heap depending on their scope and lifetime.
Objects can be created using new operator and must be deleted using delete operator to avoid memory leaks.
Smart pointers like unique_ptr and shared_ptr can be used to manage object memory automatically.
Memory leaks can be avoided by properly managing object ownership and using RAII.
Memory fragmentation ca...read more
Q28. OOP'S concepts, reference vs pointer, malloc() vs new, PL SQL questions, simple snippets output
Questions related to OOP concepts, pointers, memory allocation, PL SQL, and code snippets.
OOP concepts include encapsulation, inheritance, and polymorphism.
Pointers hold memory addresses, while references are aliases for existing variables.
malloc() allocates memory on the heap, while new allocates memory on the heap and constructs an object.
PL SQL is a procedural language used for managing data in Oracle databases.
Code snippets can have varying outputs depending on the input ...read more
Q29. Puzzle 4 tier and one spare tier
The puzzle involves stacking 4 tiers of different sizes with one spare tier. The task is to find the minimum number of moves to stack them all.
Start by placing the largest tier at the bottom and the smallest at the top.
Move the spare tier to the desired position to stack the next tier.
Repeat until all tiers are stacked.
The minimum number of moves required is 15.
Q30. what's function pointer and what's it's signature
A function pointer is a variable that stores the address of a function. Its signature includes the return type and parameter types of the function.
Function pointers allow for dynamic function calls based on the stored address
Syntax: return_type (*pointer_name)(parameter_types)
Example: void (*funcPtr)(int) = &someFunction;
Q31. There were 12 bytes of char and had to store that in 6 bytes reversing each byte.
To store 12 bytes of char in 6 bytes by reversing each byte, we can split the original bytes into pairs and reverse the order of each pair.
Split the 12 bytes into 6 pairs of 2 bytes each
Reverse the order of bytes in each pair
Store the reversed pairs in the 6 bytes of memory
Q32. How to delete the middle element of a linked list?
To delete the middle element of a linked list, find the middle element using slow and fast pointers, then remove it by adjusting the pointers.
Use slow and fast pointers to find the middle element
Adjust pointers to remove the middle element
Update the links to maintain the integrity of the linked list
Q33. have you used any windows api's?
Yes, I have used Windows API's extensively in my previous projects.
I have used Windows API's for tasks such as creating windows, handling messages, and interacting with system resources.
Examples include using functions like CreateWindow, SendMessage, and ReadFile.
I have also worked with specific Windows API's like Winsock for networking and WinINet for internet-related tasks.
Q34. Difference between stack memory and heap memory
Stack memory is allocated automatically, while heap memory is allocated manually.
Stack memory is limited and has a fixed size, while heap memory is larger and can grow dynamically.
Stack memory is faster to access than heap memory.
Stack memory is used for local variables and function calls, while heap memory is used for dynamic memory allocation.
Examples of stack memory include function call stack and local variables, while examples of heap memory include dynamically allocated...read more
IPC stands for Inter-Process Communication, which allows processes to communicate and share data with each other.
IPC enables processes to exchange data and information with each other.
Common IPC mechanisms include pipes, message queues, shared memory, and sockets.
Examples of IPC usage include communication between a parent and child process, or between different processes on a network.
Q36. Implementation of STL libraries any container class ex:- Vector
STL libraries provide efficient and easy-to-use container classes like Vector for storing and manipulating data.
STL Vector is a dynamic array that can resize itself automatically.
It provides random access to elements, similar to arrays.
Vector supports various operations like push_back, pop_back, insert, erase, etc.
Example: std::vector<int> numbers = {1, 2, 3, 4, 5};
Q37. Copy one string to another without using any standard function
Use a loop to copy characters from one string to another
Create two character arrays to store the strings
Use a loop to iterate through each character of the source string and copy it to the destination string
Add a null terminator at the end of the destination string to mark the end of the copied string
Q38. What's Design pattern used in your project?
The design pattern used in my project is the Observer pattern.
Implemented to establish a one-to-many dependency between objects.
Allows multiple objects to listen and react to changes in a subject.
Promotes loose coupling between objects.
Example: Used to notify multiple UI components when a data model changes.
Q39. How to add external API to project
To add an external API to a project, you need to first obtain the API documentation and credentials.
Obtain API documentation and credentials
Integrate API into project using appropriate libraries or frameworks
Test API functionality and handle errors appropriately
Q40. Write a program to find the second largest element in an array.
Program to find the second largest element in an array
Iterate through the array to find the largest element
Then iterate again to find the second largest element
Handle edge cases like empty array or array with only one element
Q41. Overload + operator to add two complex numbers
Overload + operator to add two complex numbers in C++.
Define a class for complex numbers with real and imaginary parts.
Overload the + operator as a member function of the class.
Return a new complex number with the sum of real and imaginary parts.
Q42. Write code to delete node from linked list
To delete a node from a linked list, update the pointers of the previous node to skip the node to be deleted.
Traverse the linked list to find the node to be deleted
Update the pointers of the previous node to skip the node to be deleted
Free the memory allocated to the node to be deleted
Q43. Which version of c++ you use
I primarily use C++17, but I am familiar with earlier versions as well.
I am comfortable working with features introduced in C++17 such as structured bindings and constexpr if
I have experience with earlier versions like C++11 and C++14
I stay updated with the latest features and improvements in C++ standards
Q44. What's compile time polymorphism
Compile time polymorphism is achieved through function overloading and templates in C++.
Compile time polymorphism allows for different functions to be called based on the arguments provided at compile time.
Function overloading is a form of compile time polymorphism where multiple functions have the same name but different parameters.
Templates in C++ allow for generic programming and compile time polymorphism by creating functions or classes that can work with any data type.
Co...read more
Q45. What is the use of Mutex
Mutex is used in multithreading to prevent multiple threads from accessing shared resources simultaneously.
Mutex stands for mutual exclusion and is used to synchronize access to shared resources in multithreaded programs.
It allows only one thread to access the shared resource at a time, preventing data corruption or race conditions.
Mutexes are typically used in critical sections of code where data integrity is important.
Example: Protecting a shared variable in a multithreaded...read more
Q46. Difference between multiprogramming and multitasking.
Multiprogramming involves running multiple programs on a single processor, while multitasking involves executing multiple tasks within a single program.
Multiprogramming allows multiple programs to be loaded into memory and executed concurrently, while multitasking involves switching between multiple tasks within a single program.
In multiprogramming, the operating system decides which program gets the processor's attention at any given time, while in multitasking, the program ...read more
Q47. Difference between multi-programming and multi-tasking.
Multi-programming involves running multiple programs on a single processor, while multi-tasking involves running multiple tasks within a single program.
Multi-programming allows multiple programs to be loaded into memory and executed concurrently, switching between them to utilize processor time efficiently.
Multi-tasking allows a single program to perform multiple tasks simultaneously, such as running multiple threads or processes within the program.
Examples of multi-programmi...read more
Q48. Bit shift 1 by 4 position from LSB
Bit shift 1 by 4 positions from LSB results in 16
Use the left shift operator (<<) to shift the bits by 4 positions
1 << 4 = 16
Q49. What is threads and programs
Threads are lightweight processes within a program that can run concurrently, allowing for multitasking. Programs are sets of instructions executed by a computer.
Threads are independent sequences of execution within a program.
Threads share the same memory space and resources, allowing for efficient communication and data sharing.
Programs are a collection of instructions that tell a computer how to perform a specific task.
Programs can be written in various programming language...read more
Q50. Find max occurance number in array
Find the number with the highest frequency in an array of strings.
Create a map to store the frequency of each number in the array.
Iterate through the array and update the frequency in the map.
Find the number with the highest frequency in the map.
Interview Questions of Similar Designations
Top Interview Questions for C Developer Related Skills
Interview experiences of popular companies
Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary
Reviews
Interviews
Salaries
Users/Month