Panel For Example Panel For Example Panel For Example

20 Common Embedded Systems Interview Questions and Answers

Author : Adrian January 06, 2026

 

1. How to write an infinite loop in C for embedded systems?

Answer: Use while(1) { } or for(;;)

 

2. Where are local variables, global variables, and dynamically allocated data stored?

Answer: Local variables reside on the stack; global variables reside in the static/data area; dynamically allocated data resides on the heap.

 

3. What does the const keyword mean?

Answer:

  • 1) Read-only.
  • 2) Using const can sometimes produce more compact code.
  • 3) It allows the compiler to protect parameters or objects that should not be modified accidentally.

 

4. What is the problem in this code?

Answer: No memory was allocated for str. Copying a string into the location pointed to by a char pointer without allocating space will cause undefined behavior and can lead to a crash, even if it appears to print correctly.

 

5. Given an array named table, define a macro to compute the number of elements

Answer: #define NTBL (sizeof(table)/sizeof(table[0]))

 

6. Write a standard MIN macro that takes two parameters and returns the smaller one

Answer: #define MIN(A,B) ((A) <= (B) ? (A) : (B))

Key points:

  • 1) Understand #define for macros. Before inline functions were standardized, macros were commonly used to produce inline code, which is important in embedded systems for performance.
  • 2) Know the ternary conditional operator. It can enable the compiler to generate better code than if-then-else in some cases.
  • 3) Enclose macro parameters in parentheses to avoid precedence issues.

 

7. What is the difference between do...while and while?

Answer: do...while executes the loop body once before testing the condition; while tests the condition before executing the loop body.

 

8. What is precompilation and when is it needed?

Answer:

  • 1) For large bodies of code that rarely change.
  • 2) When a program has multiple modules that all use the same set of include files and compilation options. In that case, the include files can be precompiled into a precompiled header.

Precompilation directives instruct the compiler to perform certain operations before the formal compilation step; they can appear anywhere in the program.

 

9. On a 32-bit machine, how many bits is a pointer?

Answer: Pointer size depends on the address bus width. On typical 32-bit platforms, pointers are 32 bits, i.e., 4 bytes.

 

10. Can a local variable have the same name as a global variable?

Answer: Yes. The local variable hides the global one. Within the function, the local variable is used instead of the global variable. Some compilers also allow multiple local variables with the same name in different inner scopes, e.g., inside separate loops.

 

11. What is the difference between a reference and a pointer?

Answer:

  • 1) A reference must be initialized; a pointer does not have to be.
  • 2) After initialization a reference cannot be reseated to refer to a different object; a pointer can point to different objects.
  • 3) There is no standard language notion of a null reference, but null pointers exist.

 

12. What does the static keyword do?

Answer: In C, static has three clear effects:

  • 1) Inside a function, a variable declared static retains its value across function calls.
  • 2) At file scope (outside functions), a static variable is accessible only to functions within that file; it is a file-local global variable.
  • 3) A function declared static at file scope can be called only by other functions in the same file; its scope is limited to that file.

 

13. What is the difference between static global variables and ordinary global variables? And static functions vs ordinary functions?

Answer: Prefixing a global (external) variable declaration with static makes it a static global variable. Both ordinary global variables and static global variables use static storage duration. The difference is scope: non-static globals are visible across the whole program (across multiple source files), while static globals are limited to the defining source file. This reduces accidental use from other files.

Converting a local variable to static changes its storage duration; converting a global variable to static changes its scope. A static function is limited in scope to the current source file and should be declared static when it is intended for internal use only. Functions intended for use outside the file should be declared in a header and defined without static.

 

14. What are the methods for interprocess communication (IPC)?

Answer: IPC methods include pipes, messages, signals, and others.

Common IPC mechanisms:

  • Unnamed pipe: a half-duplex communication channel for related processes, typically parent and child.
  • popen (advanced pipe): starts another program as a child process and communicates via a pipe.
  • Named pipe: a half-duplex channel that allows communication between unrelated processes.
  • Message queue: kernel-managed queues identified by a key; overcomes limitations of signals and pipes.
  • Semaphore: a counter used to control access to shared resources; used for synchronization within and between processes.
  • Signal: a notification mechanism to inform a process that an event has occurred.
  • Shared memory: a memory region mapped so multiple processes can access it; it is the fastest IPC method and is often paired with other mechanisms like signals for synchronization.
  • Socket: an IPC mechanism that can also be used for communication between processes on different machines.

 

15. What causes deadlock?

Answer: Deadlock occurs when concurrent processes compete for system resources and end up waiting for each other. Every process in a set waits for an event that only another process in the set can trigger, resulting in all processes being blocked.

Essential causes:

  • 1) Limited system resources.
  • 2) Unreasonable process scheduling or ordering when acquiring resources.

 

16. Four necessary conditions for deadlock

Answer:

  • 1) Mutual exclusion: a resource is assigned to at most one process at a time.
  • 2) Hold and wait: a process holds one or more resources while waiting to acquire additional ones.
  • 3) No preemption: resources cannot be forcibly taken from a process.
  • 4) Circular wait: a cycle of processes exists where each process holds a resource needed by the next process in the cycle.

When all four conditions hold, deadlock can occur and affected processes cannot proceed or release their resources, reducing system throughput.

 

17. How to handle deadlock?

Answer: Deadlock handling includes prevention, avoidance, detection, and recovery.

Prevention strategies:

  • 1) Allocate all required resources at once to break the hold-and-wait condition.
  • 2) Make resources preemptible: release already held resources if a process cannot obtain new ones.
  • 3) Order resources and require processes to request them in increasing order to prevent circular wait.

Avoidance:

Use weaker restrictions than prevention to maintain better performance. The system evaluates the safety of resource allocation requests; if granting a request would lead to an unsafe state, the request is delayed. The banker’s algorithm is a representative avoidance algorithm.

Detection:

Assign unique identifiers to processes and resources, build allocation and request tables, and periodically check for cycles or unsafe states.

Recovery:

  • 1) Preempt resources: take resources from other processes and give them to the deadlocked process.
  • 2) Abort processes: terminate one or more processes (often the least costly) until the deadlock is resolved. Cost criteria can include priority, runtime cost, and importance.

 

18. What is the difference between a process and a thread?

Answer: A process is the basic unit of resource allocation and management during execution. A thread is an execution unit within a process and is a smaller independent running unit.

Key differences:

  • 1) A process is the unit of resource allocation.
  • 2) A thread is the smallest unit of execution and the basic scheduling unit; both can execute concurrently.
  • 3) A process has its own address space; a thread shares the process address space. Creating or switching threads is generally cheaper than creating or switching processes.
  • 4) Inter-thread communication is easier because threads share global and static data; interprocess communication requires IPC mechanisms. Synchronization and mutual exclusion are critical in multithreaded programs. Multi-process programs are generally more robust because a crashed process does not directly crash other processes.
  • 5) Process switching is more resource-intensive; for frequent context switches or when shared data is required, threads are preferable.
  • 6) Execution: each process has its own entry and execution sequence; a thread cannot execute independently and requires support from the hosting process.

When to use each:

  • Use multiple processes when resource management and isolation are priorities and overhead is acceptable.
  • Use multiple threads when performance and frequent context switching are priorities and isolation requirements are lower.

 

19. Do threads share the same stack?

Answer: Each thread has its own stack. The operating system creates a main thread at program start, and program execution is performed by threads; each thread maintains its own stack.

 

20. What are the differences between TCP and UDP?

Answer: TCP and UDP are transport-layer protocols. TCP provides reliable, connection-oriented communication; UDP is connectionless and leaves reliability details to the application. Major differences:

  • 1) TCP is connection-oriented; UDP is connectionless and does not require establishing a connection before sending data.
  • 2) TCP provides reliable delivery via checksums, retransmission on loss, sequencing, sliding window flow control, and acknowledgments, ensuring data arrives intact and in order. UDP provides best-effort delivery and does not guarantee reliability.
  • 3) UDP can offer better real-time performance and higher efficiency, making it suitable for high-speed or real-time communication and broadcast scenarios.
  • 4) TCP connections are point-to-point; UDP supports one-to-one, one-to-many, many-to-one, and many-to-many communication patterns.
  • 5) TCP generally requires more system resources; UDP requires fewer resources.

When UDP can be advantageous:

  • UDP is simple and fast and is increasingly used in scenarios like real-time gaming.
  • With improved network speed and low packet loss, application-layer retransmission schemes can be used on top of UDP to achieve reliable delivery when needed.
  • TCP's built-in reliability and congestion control introduce complex handshake and retransmission behavior; when packet loss occurs, TCP may buffer later packets until missing ones are retransmitted, increasing latency. Custom retransmission on UDP can minimize latency in real-time scenarios.
Recommended Reading