C Developer

80+ C Developer Interview Questions and Answers

Updated 3 Jul 2025
search-icon

Asked in Amazon

2d ago

Q. 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

Ans.

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.

Asked in Oracle

2d ago

Q. 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
Ans.

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

illustration image

Asked in MAQ Software

3d ago

Q. 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
Ans.

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.

Asked in UBS

5d ago

Q. 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

Ans.

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.

Are these interview questions helpful?

Asked in UBS

6d ago

Q. 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

Ans.

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.

Asked in SAP

5d ago

Q. 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

Ans.

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]

C Developer Jobs

IBM India Pvt. Limited logo
Open BMC Developer 2-7 years
IBM India Pvt. Limited
4.0
Bangalore / Bengaluru
Capgemini Technology Services India Limited logo
IBM ACE +APIC Developer | 5 To 12 year | Pan India 4-6 years
Capgemini Technology Services India Limited
3.7
Bangalore / Bengaluru
Tata Consultancy Services logo
EPC Developer 2-7 years
Tata Consultancy Services
3.6
Hyderabad / Secunderabad

Asked in CGI Group

6d ago

Q. 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

Ans.

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

Q. What is the difference between a structure and a union in C++?
Ans.

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.

Share interview questions and help millions of jobseekers 🌟

man-with-laptop

Asked in Broadcom

6d ago

Q. 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 more
Ans.

Processes 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

3d ago
Q. What is dynamic memory allocation in C?
Ans.

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

Q. Convert a value from Big Endian format to Little Endian format.
Ans.

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

5d ago

Q. Const pointer and pointer to const Join in Multithreading

Ans.

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

Asked in Betsol

5d ago

Q. Constants in C, Classes and object oriented programing system concepts in c++

Ans.

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

Asked in Aczet

2d ago

Q. Time complexity of any sorting algorithm. Types of trees and linked list. How to achieve the concept of linked list in c++?

Ans.

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.

4d ago

Q. What are classes and objects in C++?

Ans.

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

1d ago

Q. Why do we use join in Multithreading?

Ans.

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

Asked in Aczet

1d ago

Q. How to create thread, what is POSIX library? How many parameters we pass while creating thread.

Ans.

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);

Asked in HCLTech

5d ago

Q. Singleton class creation (code) what is use of it ?

Ans.

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

Asked in Betsol

2d ago

Q. Scope of logic for functions, if blocks, loops, case structures.

Ans.

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.

Asked in HCLTech

4d ago

Q. Write a stack implementation using templates that can work with any data type.

Ans.

A template-based stack implementation in C++ that can handle any data type.

  • Use templates to define a generic Stack class: `template <typename T>`.

  • Implement basic stack operations: push, pop, and top.

  • Use a dynamic array (or linked list) to store stack elements.

  • Example: `Stack<int> intStack; intStack.push(5);`

  • Example: `Stack<std::string> stringStack; stringStack.push("Hello");`

Asked in Broadcom

5d ago

Q. Explain runtime polymorphism and how it works, including vptr and vtable.

Ans.

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

2d ago

Q. Object oriented programming in c++

Ans.

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

Asked in Joynext

1d ago

Q. How do you improve the code quality in the given piece of C++ code?

Ans.

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

Q. What is a zombie process?
Ans.

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

3d ago

Q. Describe a multithreading problem using synchronization where multiple threads are writing and the same thread is reading.

Ans.

Multithreading involves multiple threads reading and writing shared data, requiring synchronization to avoid data races.

  • Use mutexes to protect shared resources: std::mutex mtx; mtx.lock(); // critical section; mtx.unlock();

  • Consider read-write locks (std::shared_mutex) for scenarios with multiple readers and few writers.

  • Atomic variables (std::atomic) can be used for simple data types to avoid locking overhead.

  • Condition variables (std::condition_variable) can synchronize thread...read more

Asked in Broadcom

2d ago

Q. what is dynamic_cast where it can fail and what will happen in that case

Ans.

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

Asked in Betsol

4d ago

Q. Arrays in C, Public and private variables

Ans.

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

Q. Write a C++ class that implements debit, credit, and balance check functionalities.

Ans.

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

1d ago

Q. Memory management of variable and objects

Ans.

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

Asked in HCLTech

1d ago

Q. What is a function pointer and what is its signature?

Ans.

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;

1
2
3
Next

Interview Experiences of Popular Companies

TCS Logo
3.6
 • 11.1k Interviews
HCLTech Logo
3.5
 • 4.1k Interviews
TCS iON Logo
3.9
 • 385 Interviews
View all
interview tips and stories logo
Interview Tips & Stories
Ace your next interview with expert advice and inspiring stories

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

C Developer Interview Questions
Share an Interview
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits