Hire Trained Freshers here

Embedded C Interview Questions-Data Types, Memory, Storage Classes, Pointer, Hardware Registers, Memory Usage

Join Whatsapp here for Freshers Engineering Jobs 2025

If you’re preparing for an Embedded C interview, here are some of the most commonly asked questions along with their answers:

1. Basics of Embedded C

Q1: What is Embedded C? How is it different from standard C?

A:
Embedded C is an extension of standard C with additional features for hardware-specific programming. It is used to program microcontrollers and directly manipulate registers.
Key differences:

  • Embedded C interacts directly with hardware (I/O ports, timers, interrupts).
  • Uses memory-mapped registers, unlike standard C which primarily deals with software.
  • Requires precise timing and optimizations due to limited memory and processing power.

2. Data Types and Memory

Q2: What is the difference between signed and unsigned data types in Embedded C?

A:

  • Signed variables can store both positive and negative values.
  • Unsigned variables can only store positive values but have a larger range.

Example (assuming int is 16-bit):

signed int x = -32768 to 32767;  
unsigned int y = 0 to 65535;  

Q3: What is the size of int, char, float, and double in Embedded C?

A:
This depends on the microcontroller, but common sizes are:

Data Type 8-bit MCU 16-bit MCU 32-bit MCU
char 1 byte 1 byte 1 byte
int 2 bytes 2 bytes 4 bytes
float 4 bytes 4 bytes 4 bytes
double 4 bytes 8 bytes 8 bytes

3. Storage Classes and Memory Sections

Q4: What are different storage classes in Embedded C?

A:

  • auto – Default, local scope.
  • static – Retains value between function calls.
  • extern – Declares a global variable.
  • register – Stores variable in CPU register for fast access.
  • volatile – Prevents compiler optimizations for frequently changing variables.


Q5: What is the difference between stack and heap memory?

A:

Stack Heap
Stores function calls and local variables. Used for dynamic memory allocation (malloc).
LIFO (Last In, First Out). Managed manually (malloc, free).
Faster access. Slower but flexible.

4. Pointers & Memory Management

Q6: What is a pointer in Embedded C?

A:
A pointer is a variable that stores the memory address of another variable.

Example:

int x = 10;  
int *ptr = &x; // Pointer to x

Q7: What is the difference between pointer and array?

A:

  • Pointer stores the address of a variable.
  • Array stores multiple elements of the same type.
  • Pointers can be reassigned, arrays cannot.

Example:

int arr[] = {1, 2, 3};  
int *ptr = arr; // Pointer to array

5. Volatile, Const, and Bitwise Operations

Q8: What is the purpose of the volatile keyword in Embedded C?

A:
volatile tells the compiler that a variable can change at any time, preventing optimizations.

Example (without volatile – incorrect behavior):

int flag = 0;
while (flag == 0) { } // Compiler may optimize this into an infinite loop

Correct usage:

volatile int flag = 0; // Compiler will not optimize it

Used for registers, interrupt variables, hardware I/O.


Q9: What is the difference between const and volatile?

A:

const volatile
Prevents modification of a variable. Prevents compiler optimizations.
Example: const int x = 10; Example: volatile int x = 10;
Used for constants. Used for hardware registers, flags, etc.

Q10: What are bitwise operators, and why are they used in Embedded C?

A:
Bitwise operators manipulate individual bits of a variable. They are useful for register manipulation, setting or clearing bits.

Example:

#define LED  (1 << 2) // Define LED at bit 2
PORTA |= LED;  // Set bit 2 (turn LED on)
PORTA &= ~LED; // Clear bit 2 (turn LED off)

6. Embedded Specific Questions

Q11: How do you access hardware registers in Embedded C?

A:
Using memory-mapped registers:

#define PORTA (*(volatile unsigned int*)0x40004000)
PORTA = 0xFF; // Set all bits

Q12: What is an interrupt, and how is it handled in Embedded C?

A:
An interrupt is a signal that pauses the main program to execute a specific routine.

Example of an ISR (Interrupt Service Routine):

void __attribute__((interrupt)) ISR_Handler(void) {
   // Code to execute when an interrupt occurs
}

7. RTOS and Performance Optimization

Q13: What is the difference between polling and interrupts?

A:

Polling Interrupt
CPU continuously checks a flag. CPU gets notified only when needed.
Wastes CPU time. Efficient and real-time.
Example: Reading a button status repeatedly. Example: Executing ISR on button press.

Q14: How do you optimize memory usage in Embedded C?

A:

  • Use bitfields for flags instead of full integers.
  • Use static variables instead of global.
  • Use fixed-size arrays instead of dynamic memory allocation.

Example:

struct {
   unsigned int mode : 2;  // Only 2 bits used
   unsigned int flag : 1;  // Only 1 bit used
} config;

Q15: What are function pointers, and where are they used?

A:
Function pointers store addresses of functions and are used for callback functions, drivers, and state machines.

Example:

void (*func_ptr)(int);  // Function pointer declaration
void myFunction(int x) { }
func_ptr = myFunction;  // Assign function to pointer
func_ptr(10);  // Call function

8. Debugging & Tools

Q16: What tools are used for debugging Embedded C?

A:

  • JTAG, SWD – Hardware debugging.
  • GDB, OpenOCD – Software debugging.
  • Oscilloscope, Logic Analyzer – Signal monitoring.

Embedded C Interview Questions-Data Types, Memory, Storage Classes, Pointer, Hardware Registers, Memory Usage
Q17: How do you handle a memory leak in an embedded system?

A:

  • Avoid dynamic memory allocation (malloc/free).
  • Use static allocation whenever possible.
  • Monitor memory with profiling tools.



Join Telegram here for Embedded Engineer Freshers Jobs

Advt: BICARD-PG Diploma in Embedded Systems Design Course Training Institute Pune-Best Embedded Classes Pune