preloader
Embedded C Interview Questions

Top 50 Embedded C Interview Questions and Answers 2022 Job Preparation

author image

In this article, we have presented you with the most common and often asked interview questions on Embedded C. From this page, both freshers and experienced developers can prepare for their Interview by preparing from Embedded C Interview Questions. Here, We have covered questions on beginner, advanced and expert levels as no question is left unanswered by you at the time of the Interview. So to know more, have a look at Embedded C Interview Questions and Answers!

About Embedded C: It is a language extension of the C programming language. It is made to manage commonality issues that occur between C extensions for different embedded systems. With the help of Embedded C programmers easily develop micro-controller-based applications.

Embedded C Interview Questions

1. Explain segmentation fault error in C?

2. Explain the causes for the segmentation fault error in C?

3. Explain the ‘stack overflow’ error in C?

4. Describe whether integers are signed or unsigned?

5. Explain enumeration in C?

6. Tell me the use variable in a source file that is illustrated in another source file?

7. Tell me the way to protect a character pointer by some unexpected modifications with the pointer address?

8. Tell the use of the ‘static’ variable in C?

9. Differentiate between CISC and RISC?

10. Explain a function pointer?

11. Explain structure padding?

12. Explain dangling pointers in embedded C?

13. Tell me the function of the keyword const with an example.

14. Explain endianness?

15. Explain the functionality of realloc ()?

16. Can a parameter be both volatile and const?

17. Explain an inline function?

18. Is Count Down_to_Zero Loop better than Count_Up_Loops?

19. Can structure be passed to the functions by value?

20. Tell the size of a character, size of an integer, size of integer pointer, size of character pointer?

21. Explain a NULL pointer and its use?

22. Explain a void pointer and its use?

23. Explain ISR?

24. Tell the return type of ISR?

25. Explain interrupt latency?

26. Tell me the way to reduce interrupt latency?

27. Are we able to use any function inside ISR?

28. Are we able to use printf inside ISR?

29. Are we able to put a breakpoint inside ISR?

30. Are we able to declare static variables in a header file?

31. Can include files be nested?

32. Differentiate between hard real-time and soft real-time OS?

33. In RTOS, what type of scheduling is used?

34. Explain priority inversion?

35. Differentiate between malloc and calloc?

36. Explain a semaphore?

37. Types of Semaphores?

38. Explain a spinlock?

39. Explain virtual memory?

40. Is an embedded system useful? Why?

41. Explain the bus in a microcontroller?

42. Name the parameters that decide the size of data type for a processor?

43. Tell me the importance of watchdog timer in Embedded Systems

44. Why do ++n perform faster than n+1?

45. When to use the register modifier?

46. Explain NVIC in ARM Cortex?

47. Can we alter the interrupt priority level of the Cortex-M processor family?

48. Explain start-up code?

49. Explain which can be used semaphore or mutex or spinlock in interrupt context in Linux Kernel?

50. Tell the causes of a segmentation fault in C?


Learn More Interview Questions Here:


Embedded C Interview Questions and Answers

1. Explain segmentation fault error in C?

It is basically a runtime error, which may appear due to some cause when the code is running properly.

2. Explain the causes for the segmentation fault error in C?

  • Using a dereferenced pointer (it means a pointer that may not have a proper address/ memory location to point).
  • If you access a read-only memory area. In that case, the code shows a segmentation fault error.
  • It may also appear when you release a memory (using a pointer), which is already freed.
  • Segmentation fault is the reason for the stack overflow error in C.

3. Explain the ‘stack overflow’ error in C?

This error may appear if the program attempts to utilize the memory beyond its maximum limit or a pointer surpasses the stack limitations (boundaries). When this error appears the program ends and does not run further instructions. Therefore, we must be alert while using the pointer and limit boundaries.

4. Describe whether integers are signed or unsigned?

As per the C standard, an integer data type is signed by default. So if you make an integer variable, it can reserve both negative and positive values.

5. Explain enumeration in C?

An enumeration in C is a user-defined data type. Enum includes a set of named constant integers. Using the enumeration keyword, we can declare an enum type by utilizing the enum tag (optional) and a list of named integers.

6. Tell me the use variable in a source file that is illustrated in another source file?

“extern” keyboard is used to declare a variable that permits using the variable in another file.

7. Tell me the way to protect a character pointer by some unexpected modifications with the pointer address?

Constant character pointer (const char*) stops the unexpected modifications with the pointer address in the string.

8. Tell the use of the ‘static’ variable in C?

  • A static variable can’t be redeclared; it means if it is already declared in a function then it won’t be redeclared on each function call, therefore, static can maintain the value.
  • Its scope is local but it is active till the end of the program.
  • Normally, it is used to count something, like, there is the function openBankAccount() which calls whenever a new account opens in the bank. So, to count the total number of the new accounts opened, we can declare a static variable in the function and can improve it on each function call.

9. Differentiate between CISC and RISC?

  • Reduced Instruction Set Computer stands for RISC, does not include a memory unit unlike Complex Instruction Set Computer (CISC) does.
  • Also, RISC is a moderately faster processor than CISC related to calculations.
  • RISC assures simple decoding of operations, which a CISC processor doesn’t.
  • Lastly, RISC consumes a very low implementation time compared to CISC.

10. Explain a function pointer?

A function pointer is a pointer that points to a function rather than to a variable. And this is exactly where a function pointer is different from the class of other pointers. Basically, a function pointer stores the address of a particular function to be profited from the concerned program through function invoking.

11. Explain structure padding?

Padding is the induction of duplicate bytes into a specific structure. It is the function of the compiler to ingest some additional bytes among the units of a structure or a union. This is known as the process of padding. Basically, structure padding is used for data type orientation. Thus, structure padding ends up increasing the performance quotient of the processor.

12. Explain dangling pointers in embedded C?

Dangling pointers are abnormalities that occur due to the destruction of a referencing object. It is called dangling because the pointer is basically pointing to a ghost memory to the one that is not at its disposal. Therefore, it gives elevation to the segmentation fault.

13. Tell me the function of the keyword const with an example.

Keyword const makes a variable to read-only type. For example const int iData=0; at the time of compilation, the keyword const primarily works as an indication to the compiler that the value of the declaring object is not subject to additional modification. So, the keyword is unable to be reassigned at runtime.

14. Explain endianness?

It is the order of bytes to reserve data in memory and it also defines the order of byte transmission through a digital link.

15. Explain the functionality of realloc ()?

It is primarily used to resize the allotment of memory. Technically, realloc() takes in two arguments. The first argument is the pointer to the previous allocation of memory whereas the second argument is the reference to the new size.

16. Can a parameter be both volatile and const?

Yes, a volatile cause can modify unexpectedly whereas the Const cause program should not change it.

17. Explain an inline function?

  • Inline function is a component to improve the execution time of the program and decrease function calling overhead.
  • With inline, the compiler substitutes the function call statement with the function code itself. This compilation does not need to jump to another location to perform the function.
  • The disadvantage contains increases in the executable size because of code expansion.

18. Is Count Down_to_Zero Loop better than Count_Up_Loops?

Yes, count Down_to_Zero Loop is better than Count_Up_Loops. The main reason for it is that at loop termination, comparison to zero can be boosted by the compiler. Most processors have instructions of comparing to zero and because of it; they don’t require loading the loop variable and the maximum value and then subtracting them, and then comparing to zero. That is why the Count Down_to_Zero loop is better.

19. Can structure be passed to the functions by value?

Yes, it is possible but passing structure by its value to a function is not a good practice for programming languages. If we pass the structure by value and function modifies some of those values then the changed values will not be reflected in the caller function. Also, if the structure is large, then passing the structure by value represents copying the whole structure to the function argument stack which can delay the code by a considerable amount.

20. Tell the size of a character, size of an integer, size of integer pointer, size of character pointer?

  • The size of a character is 1 byte.
  • The size of an integer is 4 bytes.
  • The size of the integer pointer and character is 8 bytes on a 64-bit machine and 4 bytes on a 32-bit machine.

21. Explain a NULL pointer and its use?

The null pointer is a pointer that doesn’t point to any reasonable location. We represent a pointer to be null when we want to assure that the pointer doesn’t point to any reasonable location and not to use that pointer to modify anything. If we sip using a null pointer, then we are not able to verify whether this pointer points to any reasonable location or not.

22. Explain a void pointer and its use?

The void pointer points to a variable that can be of any type. Other pointers point to a particular type of variable whereas void pointer can point to any data type whether it is a standard data type (int, char, etc) or user-defined data type (union, structure, etc.).

23. Explain ISR?

ISR Stands for Interrupt Service Routine as an interrupt handler, a callback subroutine that is called when an interrupt is discovered.

24. Tell the return type of ISR?

Interrupt Service Routine does not return anything as there is no caller in the program to read the returned values.

25. Explain interrupt latency?

Interrupt latency is the time needed for an ISR to respond to an interrupt.

26. Tell me the way to reduce interrupt latency?

Interrupt latency can be reduced by writing an eshort ISR routine and by not slowing interrupts for more time.

27. Are we able to use any function inside ISR?

Until the function is not invoked by any other portion of the code we can use it inside ISR.

28. Are we able to use printf inside ISR?

No, the printf function is not supported inside ISR because printf function is not reentrant, thread-safe, and uses dynamic memory allotment which consumes a lot of time and affects the speed of an ISR up to a high extent.

29. Are we able to put a breakpoint inside ISR?

It is not a good idea to put a breakpoint inside ISR because debugging will consume more time and a difference of half or more seconds will lead to the different behavior of hardware. Definitive logs are a better choice to debug ISR.

30. Are we able to declare static variables in a header file?

No, we cannot declare a static variable in a header file without defining it. So we have to define a static variable in the header file. But accomplishing so, the outcome will be having a private copy of that variable in each source file which contains the header file. So it is not wise to declare a static variable in the header file unless you are haggling with a different scenario.

31. Can include files be nested?

Yes, include files that can be nested any number of times. But you have to ensure that the same file is not included twice. There is no limit to including the number of header files but the number can be compiler dependent, as multiple header files may lead your computer to run out of stack memory.

32. Differentiate between hard real-time and soft real-time OS?

A Hard real-time system rigidly sticks to the deadline associated with the task. Even once, if the system fails to fulfill the deadline, the system is believed to have failed. Whereas in a soft real-time system skipping a deadline is permitted. In this type of system, a critical real-time task obtains priority over other tasks and controls that priority until it finishes.

33. In RTOS, what type of scheduling is used?

RTOS uses pre-emptive scheduling. In this type of scheduling, a higher priority task can stop a running process and the stopped process will be resumed later.

34. Explain priority inversion?

If two tasks share a single resource, then the one that has the higher priority will execute first. Yet, if the lower-priority task is consuming the shared resource when the higher-priority task becomes ready, then the higher-priority task needs to wait for the lower-priority task to finish; this is known as priority inversion.

35. Differentiate between malloc and calloc?

They both are memory management functions. They are utilized to assign memory dynamically. There is not much difference between them except one that the memory that is assigned by calloc is initialized with 0.

36. Explain a semaphore?

It is a variable or abstract data type which manages access to a standard resource by many processes.

37. Types of Semaphores?

  • Binary semaphore: This semaphore only has two values (0 and 1). The value is set to 1 by the process in charge when the resource is present.
  • Counting semaphore: This semaphore has a value greater than one. It is used to manage access to a pool of resources.

38. Explain a spinlock?

If a resource is locked, a thread that likes to use that resource will repetitively check whether the resource is available. At that time, the thread may create a loop and repetitively looks for the resource without doing any important work.

39. Explain virtual memory?

Virtual memory is part of memory management processes and it makes an illusion that the system has enough memory. In other terms, you can say that virtual memory is a coating of indirection.

40. Is an embedded system useful? Why?

With an embedded system, it is feasible to replace dozens of hardware input buffers, logic gates, output drivers, timing circuits, etc. with a relatively affordable microprocessor.

41. Explain the bus in a microcontroller?

It is a way to move the data quickly via digital signals. There are three types of internal buses available that are data bus, address bus, and control bus which are related to the processor. All these jointly make up the system bus.

42. Name the parameters that decide the size of data type for a processor?

For the size of the data type, a compiler is the one who is responsible but when OS allows that. If it is not permitted by the OS, then the OS decides the size.

43. Tell me the importance of watchdog timer in Embedded Systems

It is a timing device with a predefined time gap. During that gap, some event may happen, or else the device causes a time-out signal. It is used to reset to the real state whenever some improper events take place which can lead to system malfunction. It is usually used by counter devices.

44. Why do ++n perform faster than n+1?

The expression ++n needs a single machine order such as INR to carry out the increment function. In the case of n+1, other than INR, other instructions are needed to load the value of n. That is why ++n performs faster.

45. When to use the register modifier?

The register modifier is used when a variable is predicted to be heavily used and holding it in the CPU’s registers will drive the performance faster.

46. Explain NVIC in ARM Cortex?

NVIC (stands for Nested Vector Interrupt Controller) in the Cortex-M processor family is an instance of an interrupt controller with incredibly adjustable interrupt priority management. It allows programmable priority levels, automated nested interrupt support, along with authorization for multiple interrupt masking, whilst still being very comfortable to use by the developer.

47. Can we alter the interrupt priority level of the Cortex-M processor family?

Yes, we can alter the interrupt priority level of the Cortex-M processor family.

48. Explain start-up code?

It is called earlier to the main function; it makes an essential platform for the application. It is a little block of code that is written in assembly language.

49. Explain which can be used semaphore or mutex or spinlock in interrupt context in Linux Kernel?

We can use spinlocks for locking in interrupt context whereas we cannot use Semaphore or Mutex for interrupt context in Linux Kernel

50. Tell the causes of a segmentation fault in C?

  • Tried to write on read-only memory (such as code segment).
  • Dereferencing NULL pointers.
  • A buffer overflow (try to access the array beyond the boundary) is also a reason for the segmentation fault.
  • Trying to use a nonexistent memory address (outside process’s address space).
  • A stack overflow is also induced by the segmentation fault.
  • Trying to access memory of the program which you don’t have access to (such as kernel structures in process context).

Want to prepare for these languages:

Recent Articles