
Embedded C Interview Guide
- ارسال شده توسط Reza Mehrabani
- تاریخ جولای 27, 2025
- دسته بندی Embedded system interview preparation
- نظرات 0 نظر
Embedded C Interview Guide
Embedded C is a powerful language for developing embedded systems, known for its efficiency and portability. This guide provides common interview questions and answers to help you excel in your Embedded C interview.
Interview Questions for Freshers
1. What is Embedded C Programming, and How Does It Differ from C?
Answer: Embedded C is an extension of C for embedded systems, using the same syntax. Differences:
- Standard C: Hardware-independent, used for desktop applications.
- Embedded C: Hardware-dependent, optimized for limited resources.
2. What is Startup Code?
Answer: Startup code runs before main, initializing the stack and interrupt vectors, typically in assembly.
3. What is an ISR?
Answer: An Interrupt Service Routine (ISR) handles interrupts and must be short and fast.
4. What is a Void Pointer, and Why is It Used?
Answer: A void pointer can point to any data type for flexibility:
int num = 20;
void *ptr = #
printf("%d", *(int*)ptr);
5. Why Use the volatile Keyword?
Answer: volatile prevents compiler optimization for variables that may change unexpectedly:
volatile int sensor_value;
6. Differences Between const and volatile
Answer:
const: Makes a variable read-only.volatile: Prevents compiler optimization.
7. What is the Concatenation Operator?
Answer: The ## operator concatenates macro arguments:
#define CONCAT(x, y) x##y
int main() {
int xValue = 20;
printf("%d", CONCAT(x, Value));
}
8. What is Interrupt Latency?
Answer: Time taken for an ISR to respond to an interrupt.
9. Using a Variable from One Source File in Another
Answer: Use extern:
// file1.c
int global_variable = 10;
// file2.c
extern int global_variable;
printf("%d", global_variable);
10. What is a Segmentation Fault?
Answer: Occurs when accessing prohibited memory, like NULL pointers or out-of-bounds arrays.
11. Inline vs. Macro Functions
Answer: Macros are preprocessor-expanded, lack type checking; inline functions are compiler-expanded, safer.
12. Can a Variable Be volatile and const?
Answer: Yes, const prevents program modification, while volatile allows external changes.
13. Declaring static in a Header File
Answer: Possible but not recommended, as each source file gets a separate copy.
14. Pre-Decrement vs. Post-Decrement
Answer:
int x = 100, y;
y = --x; // y = 99, x = 99
y = x--; // y = 100, x = 99
15. What is a Reentrant Function?
Answer: A function that can be interrupted and re-entered safely.
Interview Questions for Experienced Candidates
16. Counting Up vs. Down Loop
Answer: Counting down to zero is faster due to optimized zero comparison.
17. What is a Null Pointer?
Answer: Points to no valid memory:
int *ptr = NULL;
18. Meaning of These Declarations
Answer:
const int x;: Read-only integer.const int *x;: Pointer to read-only integer.int *const x;: Constant pointer to an integer.int const *x const;: Constant pointer to a read-only integer.
19. Why is ++i Faster Than i+1?
Answer: ++i uses a single machine instruction, while i+1 requires loading and addition.
20. What Causes Segmentation Faults, and How to Avoid Them?
Answer: Causes: Dereferencing NULL/freed pointers, accessing out-of-bounds arrays. Prevention: Initialize pointers, check array bounds.
21. Is printf Recommended in an ISR?
Answer: No, printf is non-reentrant and causes delays.
22. Can You Pass Parameters to or Return Values from an ISR?
Answer: No, ISRs cannot accept parameters or return values.
23. What is Virtual Memory in Embedded C?
Answer: Virtual memory uses paging to reduce memory usage.
24. What’s Wrong with This Code?
int square(volatile int *p) {
return (*p) * (*p);
}
Answer: *p may change between dereferences. Corrected:
long square(volatile int *p) {
int x = *p;
return (long)x * x;
}
25. Is This ISR Code Correct?
__interrupt double calculate_circle_area(double radius) {
double circle_area = 3.14 * radius * radius;
printf("Area = %f", circle_area);
return circle_area;
}
Answer: No, ISRs cannot return values, accept parameters, or use printf.
26. What is the Output of This Code?
void demo(void) {
unsigned int x = 10;
int y = -40;
if (x + y > 10) {
printf("Greater than 10");
} else {
printf("Less than or equals 10");
}
}
Answer: Output: Greater than 10, as y is converted to unsigned.
27. Causes of Interrupt Latency and Reduction
Answer: Causes: Hardware synchronization, CPU pipeline, long ISRs. Reduction: Short ISRs, better scheduling.
28. Protecting a Character Pointer
Answer: Use char *const.
29. Wild vs. Dangling Pointers
Answer:
- Wild: Uninitialized pointer.
- Dangling: Pointer to freed memory.
30. Difference Between #include "..." and #include <...>
Answer: "..." searches the current directory first, <...> searches standard directories.
31. What is a Memory Leak, and How to Avoid It?
Answer: Memory leaks occur when allocated memory isn’t freed. Avoid with free and tools like Valgrind.
Embedded C Programming
32. Multiply a Number by 9 Efficiently
#include <stdio.h>
int main() {
int num;
printf("Enter number: ");
scanf("%d", &num);
printf("%d", (num << 3) + num);
return 0;
}
33. Swap Two Variables
int a = 20, b = 30, temp;
temp = a;
a = b;
b = temp;
34. Check If a Number is a Power of 2
#include <stdio.h>
int main() {
int num;
printf("Enter number: ");
scanf("%d", &num);
if (num && !(num & (num - 1)))
printf("Number is a power of 2");
else
printf("Number is not a power of 2");
return 0;
}
35. Print Numbers 1 to 100 Without Conditionals
#include <stdio.h>
int main() {
int i = 0;
while (100 - i++)
printf("%d ", i);
return 0;
}
36. MIN Macro
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
Conclusion
Preparing for an Embedded C interview requires understanding C concepts and optimization for embedded systems. Practice these questions to excel in your interview.
ما کنار هم رشد می کنیم.
شما همچنین ممکن است دوست داشته باشید
Advanced FreeRTOS Concepts, Porting, and Real-Time

