Firmware Development Interview Questions and Answers

Firmware Development Interview Questions and Answers

Last updated on 21st Oct 2020, Blog, Interview Question

About author

Anandraj ((Sr Technical Manager ) )

High level Domain Expert in TOP MNCs with 8+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 12547 Ratings 2374

Firmware literally means a software running inside an application specific chip (like micro controller). So development of such software is firmware development. PC and mobiles use general purpose processors, so their software development cannot be called as firmware.

1. What Do You Understand Firmware?


Firmware is basically software that is embedded on a piece of hardware categorized as Non-volatile memory. Non-volatile (NVMe) is a semiconductor technology that does not require a continuous power supply to retain the data or the coded program stored in a computing device like flash drives, cameras, remote control etc. Firmware provides a standardized operating environment for complex devices like camera, television sets etc. which does not need a continuous power supply.

2. What Is The Difference Between A Driver And Firmware?


Device drivers are dependent on the operating system and hardware. A driver acts as a translator between the hardware device and the programs or operating systems on which the hardware is installed. Firmware is a software program permanently installed into a hardware device such as a keyboard, hard drive, BIOS, or video cards and is independent to operate the hardware accordingly. It draws power from the source on which it runs.

3. What Is The Firmware Of A Computer?


Firmware is the stored data on a computer or another hardware device’s read-only memory (ROM). It consists of instructions of the device’s operating procedure. Firmware such as the ROM, BIOS of any computing devices like laptop, Smartphone or personal computers may contain only elementary functions of a device. Firmware such as the program of the embedded system may be the only program that runs on the system and provides all of its functions.

4. Is Embedded Software A Firmware?


Embedded System usually refers to a specific instance of some hardware that’s designed to be embedded into an application. Firmware is the software which is being installed during the manufacturing of the system. The name clearly suggests that it is firmly embedded in the hardware. If we consider the system is a PC, BIOS is its firmware.

5. What Language Is Used To Write Firmware?


Firmware is typically written in a low-level language (be it C or assembly) as compared to other languages. It can be easily compiled and assembled into machine code and placed in a known position on the storage, where the hardware, during its startup process can read from the location and initiate that code.

6. What Are The Common Examples Of Firmware?


Firmware is a set of instructions that are running on our routers, DVD Player, Smartphones etc. More sophisticated firmware runs on a computer that requires a continuous power supply. BIOS are one such firmware. Another example is a microcontroller, a part of the microprocessor that instructs the microprocessor what actions to take.

7. What Is Firmware Of Microcontroller?


Firmware is a program that is installed in any microcontroller based system, usually stored in flash memory. The bootloader is a small program which facilitates the programming of these flash memories.

8. What Is Embedded Software Design?


Embedded software is written to control machines or devices that are not perceived as computers. It is being designed for the particular hardware that is operated upon and has time and memory constraints. These machines don’t need a power supply and can be switched on and off randomly. Instructions installed in it cannot be modified and for which the data doesn’t need to be saved.

Subscribe For Free Demo

Error: Contact form not found.

9. What Do We Know By Embedded Firmware Design?


Embedded firmware is the memory chip which stores specialized instructions running on an embedded device to manage its functions. Firmware in any embedded system provides the same purpose as ROM but can be updated more easily as compared to firmware on non-volatile equipment. Updations are essential for better adaptability to conditions or interconnecting with additional and modern equipment.

10. Which Programming Language Is Used For Microcontrollers?


Microcontrollers were initially programmed in its assembly language, but nowadays there are many programming languages available and are being used to target microcontrollers. These languages are nowadays being designed especially for the purpose or versions of general purpose languages such as the C programming language.

11. What Is Firmware In An Operating System?


Firmware in an operating system is also known as a bootstrap program, known as BIOS, which initializes the operating system. It is mounted in ROM (a non-volatile memory, whose contents are permanent). Firmware locates the kernel of the operating system (kernel is part of the operating system) and loads it into primary memory (RAM) at the time of the computer startup. Firmware of this type needs to be updated regularly to keep the system compatible with other modern devices.

12. What Do We Mean By A Firmware Update?


Most of the modern day gears and other state of art appliances, that are being invented for use nowadays is more or less the computer, be it an audio or video device. In these devices, the manufacturer makes improvements to the firmware that operates the device. These improvements are released as firmware updates and are generally updated through the internet.

13. What Is An Embedded Language? Which Programming Language Is Used In Embedded Systems?


A programming language is a language that has been used for coding in the firmware application. Examples of embedded languages are VBA for Microsoft applications and various other versions of LISP in programs such as Emacs & AutoCAD. C remains the most widely used and is being accepted in the embedded programming language, with compilers available for almost every microprocessor, microcontroller and processor core on the market. However, this language wasn’t designed or intended for making firmware.

14. What Are Real Times Embedded Systems?


Real-time systems are specially designed computers that are supposed to monitor, respond to, or control an external environment, connected to the computer system through sensors, actuators, and other input-output interfaces. These environments generally consist of physical or biological objects of any form and structure. Sometimes humans are part of the connected as an external world, but a wide range of other natural and artificial objects, as well as animals, are also possible in this system. These computer systems must meet various timing and other constraints that are imposed on it by the real-time behavior of the external world for which it is interfaced. That’s why it is known as real time. Another name for these systems is reactive systems; because their primary purpose is to react to signals from their environment. A real-time computer system may be a component of a larger system in which it is embedded; reasonably, such a computer component and is called as an embedded system.

15. Why Is Embedded System Useful?


With an embedded system, it is possible to replace dozens or even more of hardware logical gates, input buffers, timing circuits, output drivers, etc. with a relatively cost-effective microprocessor.

16. Explain What Are Real-time Embedded Systems?


Real-time embedded systems are computer systems that monitor, respond or control an external environment. This environment is connected to the computer system through actuators, sensors, and other input-output interfaces.

17. What Do You Understand By A Microcontroller?


The microcontroller is a self-contained device with peripherals, memory and a processor that can be used as an embedded system.

18. Mention The Difference Between Microprocessor And Microcontroller?


Microprocessor manages the resource (I/O, memory) which lies outside of its own architecture. Microcontrollers have I/O, memory, etc. inbuilt and specifically designed for controlling applications.

19. What Is Dma? How Does Dma Deal With A Microcontroller?


Direct Memory Access (DMA) is a feature provided by some computer bus architectures which permits data to be sent directly from an external device (such as a disk drive) to the memory on the computer’s motherboard. DMA address deals with such physical addresses. It is an appliance which directly drives the data and address bus during data transfer. So, it is purely a physical address.

20. Explain Interrupt Latency? How Can You Reduce It?


In computing, interrupt latency is the delayed time when an interrupt is generated to when the cause of the interrupt is serviced. For many operating systems, devices are serviced as soon as the device’s interrupt handler is executed. By writing some minor ISR routines, interrupt latency can be reduced and make the system efficient.

21. Mention What Are Buses Used For Communication In An Embedded System?


In an embedded system, following are the buses used for communication:

  • I2C: used for communication between multiple ICs
  • CAN: used in automobiles with centrally controlled network
  • USB: used for communication between CPU and devices like mouse, etc.
  • While ISA, EISA, PCI are the standard buses for parallel communication being used in PCs & other network devices.

22. List Out The Various Uses Of Timers In An Embedded System?


Timers in embedded system is used in multiple ways:

  1. 1. Real Time Clock (RTC) for the computer system
  2. 2. Initiating an event after the preset time delay
  3. 3. Initiating an event after the comparison of preset times
  4. 4. Calculate the value in timer on any event
  5. 5. Finding the time interval between two eventsTime slicing for different tasks
  6. 6. Time division multiplexing
  7. 7. Setting up of various tasks in RTOS

23. What Is A Watchdog Timer?


A watchdog timer (WDT) is a hardware that automatically initiates a system reset if the main program neglects to service it. It is often used to reset an embedded device that hangs because of a software or hardware malfunction.

24. Explain The Need For An Infinite Loop In Embedded Systems?


Embedded systems need infinite loops for repeatedly processing and monitoring the state of the program for exceptional errors. For instance, issues such as memory outage or divide by zero, etc. that might just happen during the runtime and are being verified.

25. List Out Some Of The Commonly Found Errors In Embedded Systems?


Some of the commonly found errors in embedded systems are:

  1. 1. Damage of memory devices due to static discharges and transient current.
  2. 2. Address line malfunctioning due to a short circuit
  3. 3. Malfunctioning of Data lines
  4. 4. Due to garbage or errors, some memory locations become inaccessible for storage
  5. 5. Wrong insertion of memory devices into memory slots
  6. 6. Wrong control of signals

26. What Is Semaphore? What Are The Types Of Semaphore?


Semaphore is an abstract data store which is used to control the resource accesses across the different threads of execution or across different processes.

There are basically two types of semaphores:

  • Binary semaphore which can take only 0, 1 values. (Used when there is contention for a single resource entity).
  • Counting semaphore which can take incremental values to a certain limit (used when a number of resources is limited).

27. When Should We Use The Recursion Function? Mention What Happens When Recursion Functions Are Declared Inline?


Recursion function should be used when we are aware of the number of recursive calls is not excessive. Inline functions property says whenever it will call, it will copy the full definition of the function. Recursive functions declared as inline, creates the burden for the compiler’s execution.

Course Curriculum

Best Firmware Development Training from MNC Experts

  • Instructor-led Sessions
  • Real-life Case Studies
  • Assignments
Explore Curriculum

28. Explain Whether We Can Use Semaphore Or Mutex Or Spinlock In Interrupt Context In Linux Kernel?


Semaphore or Mutex can’t be used for interrupt contexts in Linux Kernel. While spinlocks can be safely used for locking in interrupt context.

29. What Does A Firmware Engineer Do?


Firmware is the programmable content in electronic hardware devices, such as remote controls, mobile phones and medical devices that provide directions to the device on how to operate. Firmware engineers create and execute these instructions, called algorithms, which enable the hardware to function properly.

30. What is the volatile keyword?


The volatile keyword is a type qualifier that prevents the objects from the compiler optimization. According to C standard, an object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. You can also say that the value of the volatile-qualified object can be changed at any time without any action being taken by the code. If an object is qualified by the volatile qualifier, the compiler reloads the value from memory each time it is accessed by the program that means it prevents from cache a variable into a register. Reading the value from memory is the only way to check the unpredictable change of the value.

31. What is the use of volatile keyword?


The volatile keyword is mainly used where we directly deal with GPIO, interrupt or flag Register. It is also used with a global variable or buffer which shared between the threads.

32. What is the difference between the const and volatile qualifiers in C?


The const keyword is compiler-enforced and says that the program could not change the value of the object that means it makes the object nonmodifiable type. Let us see an example,

  • const int a = 0;

If we will try to modify the value of “a”, we will get the compiler error because “a” is qualified with const keyword that prevents to change the value of the”a” (integer variable).

 Another side, volatile prevents any compiler optimization and says that the value of the object can be changed by something that is beyond the control of the program and so that compiler will not make any assumption about the object. Let see an example,

  • volatile int a;

When the compiler sees the above declaration then it avoids to make any assumption regarding the “a” and in every iteration read the value from the address which is assigned to the “a”.

33. Can a variable be both constant and volatile in C?


Yes, we can use both constant and volatile together. One of the great use of volatile and const keyword together is at the time of accessing the GPIO registers. In the case of GPIO, its value will be changed by the ‘external factors’ (if a switch or any output device is attached with GPIO), if it is configured as an input. In that situation, volatile plays an important role and ensures that the compiler always read the value from the GPIO address and avoid to make any assumption.

After using the volatile keyword, you will get the proper value whenever you are accessing the ports but still here is one more problem because the pointer is not const type so it might be your program change the pointing address of the pointer. 

34. Can we have a volatile pointer?


Yes, we can create a volatile pointer in C language.

  • // piData is a volatile pointer to an integer.
  • int * volatile piData;

35. What is ISR?


An ISR refers to the Interrupt Service Routines. These are procedures stored at specific memory addresses which are called when a certain type of interrupt occurs. The Cortex-M processors family has the NVIC that manages the execution of the interrupt.

36. Can we pass any parameter and return a value from the ISR?


An ISR returns nothing and not allow to pass any parameter. An ISR is called when a hardware or software event occurs, it is not called by the code, so that’s the reason no parameters are passed into an ISR.

In the above line, we have already read that the ISR is not called by the code, so there is no calling code to read the returned values of the ISR. It is the reason that an ISR is not returned any value.

37. What is interrupt latency?


It is an important question that is asked by the interviewer to test the understanding of Interrupt. Basically, interrupt latency is the number of clock cycles that are taken by the processor to respond to an interrupt request. This number of the clock cycle is count between the assertions of the interrupt request and the first instruction of the interrupt handler.

Interrupt Latency on the Cortex-M processor family

The Cortex-M processors have very low interrupt latency. In the below table, I have mentioned, Interrupt latency of Cortex-M processors with zero wait state memory systems.

ProcessorsCycles with zero wait state memory

38. How do you measure interrupt latency?


With the help of the oscilloscope, we can measure the interrupt latency. You need to take the following steps.

  1. 1. First takes two GPIOs.
  2. 2. Configure one GPIO to generate the interrupt and second for the toggling (if you want you can attach an LED).
  3. 3. Monitor the PIN (using the oscilloscope or analyzer) which you have configured to generate the interrupt.
  4. 4. Also, monitor (using the oscilloscope or analyzer) the second pin which is toggled at the beginning of the interrupt service routine.
  5. 5. When you will generate the interrupt then the signal of both GPIOs will change.

The interval between the two signals (interrupt latency) may be easily read from the instrument.

39. How to reduce interrupt latency?


The interrupt latency depends on many factors, some factors I am mentioning in the below statements.

  • Platform and interrupt controller.
  • CPU clock speed.
  • Timer frequency
  • Cache configuration.
  • Application program.

So using the proper selection of platform and processor we can easily reduce the interrupt latency. We can also reduce the interrupt latency by making the ISR shorter and avoid to calling a function within the ISR.

40. What is the difference between an uninitialized pointer and a null pointer?


An uninitialized pointer is a pointer that points unknown memory location. The behavior of the uninitialized pointer is undefined. If you try to dereference the uninitialized pointer code behavior will undefine.

According to C standard, an integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. The behavior of the uninitialized pointer is defined. When you try to dereference the null pointer then your code will crash.

41. What are the causes of Interrupt Latency?


  1. 1. The first delay is typically caused by hardware: The interrupt request signal needs to be synchronized to the CPU clock. Depending on the synchronization logic, up to 3 CPU cycles may expire before the interrupt request has reached the CPU core.
  2. 2. The CPU will typically complete the current instruction, which may take several cycles. On most systems, divide, push-multiple or memory-copy instructions are the most time-consuming instructions to execute. On top of the cycles required by the CPU, additional cycles are often required for memory accesses. In an ARM7 system, the instruction STMDB SP!,{R0-R11, LR} typically is the worst-case instruction, storing 13 registers of 32-bits each to the stack, and takes 15 clock cycles to complete.

The memory system may require additional cycles for wait states.

After completion of the current instruction, the CPU performs a mode switch or pushes registers on the stack (typically PC and flag registers). Modern CPUs such as ARM generally perform a mode switch, which takes fewer CPU cycles than saving registers.

Pipeline fill: Most modern CPUs are pipelined. Execution of an instruction happens in various stages of the pipeline. An instruction is executed when it has reached its final stage of the pipeline. Since the mode switch has flushed the pipeline, a few extra cycles are required to refill the pipeline.

42. Can we use any function inside ISR?


Yes, you can call a function within the ISR but it is not recommended because it can increase the interrupt latency and decrease the performance of the system. If you want to call a nested function within the ISR, you need to read the datasheet of your microcontroller because some vendors have a limit to how many calls can be nested.One important point needs to remember that the function that is called from the ISR should be re-entrant. If the called function is not re-entrant, it could create the issues.

For example,

If the function is not reentrant and supposes that it is called by another part of the code beside the ISR. So the problem will be invoked when if the ISR calls the same function which is already invoked outside of the ISR?

43. What is a nested interrupt?


In a nested interrupt system, an interrupt is allowed to any time and anywhere even an ISR is being executed. But, only the highest priority ISR will be executed immediately. The second highest priority ISR will be executed after the highest one is completed.

The rules of a nested interrupt system are:

  1. 1. All interrupts must be prioritized.
  2. 2. After initialization, any interrupts are allowed to occur anytime and anywhere.
  3. 3. If a low-priority ISR is interrupted by a high-priority interrupt, the high-priority ISR is executed.
  4. 4. If a high-priority ISR is interrupted by a low-priority interrupt, the high-priority ISR continues executing.
  5. 5. The same priority ISRs must be executed by time order

If you want to learn STM32 from scratch, you should follow this course Mastering Microcontroller with Embedded Driver Development. The course contains video lectures of 18.5-hours length covering all topics like, Microcontroller & Peripheral Driver Development for STM32 GPIO, I2C, SPI, USART using Embedded C.

44. What is NVIC in ARM Cortex?


The Nested Vector Interrupt Controller (NVIC) in the Cortex-M processor family is an example of an interrupt controller with extremely flexible interrupt priority management. It enables programmable priority levels, automatic nested interrupt support, along with support for multiple interrupt masking, whilst still being very easy to use by the programmer.

The Cortex-M3 and Cortex-M4 processors the NVIC supports up to 240 interrupt inputs, with 8 up to 256 programmable priority levels

45. Can we change the interrupt priority level of Cortex-M processor family?


Yes, we can.

46. Why “C” language mostly preferred than assembly language?


C helps programmers focus on the structure of the code rather than the low-level demands of the CPU. They can organize code into components, such as functions and files and they have ways of managing the complexity of a project; without thinking about the nitty-gritty of issues such as how function calls work.

Since C is a portable language, code can be organized into general-purpose libraries that can be used on any platform, often with no modification. It is a great weapon against ‘reinventing the wheel.

47. What is the start-up code?


A start-up code is called prior to the main function, it creates a basic platform for the application. It is a small block of code that is written in assembly language.

There are the following parts of the start-up code.

  • Declaration of the Stack area.
  • Declaration of the Heap area.
  • Vector table.
  • Reset handler code.
  • Other exception handler code.

48. What are the start-up code steps?


Start-up code for C programs usually consists of the following actions, performed in the order described:

  1. 1. Disable all interrupts.
  2. 2. Copy any initialized data from ROM to RAM.
  3. 3. Zero the uninitialized data area.
  4. 4. Allocate space for and initialize the stack.
  5. 5. Initialize the processor’s stack pointer.
  6. 6. Create and initialize the heap.
  7. 7. Enable interrupts.
  8. 8. Call main.

49. Infinite loops often arise in embedded systems. How do you code an infinite loop in C?


In embedded systems, infinite loops are generally used. If I talked about a small program to control a led through the switch, in that scenario an infinite loop will be required if we are not going through the interrupt.

There are different ways to create an infinite loop, here I am mentioning some methods.

Method 1:

  • while(1)
  • {
  •   // task
  • }

Method 2:

  • for(;;)
  • {
  •   // task
  • }

Method 3:


  • goto Loop;

50. Difference between RISC and CISC processor?


The RISC (reduced instruction set computer) and CISC (Complex instruction set computer) are the processors ISA (instruction set architecture).

There are the following difference between both architecture:

AcronymIt stands for ‘Reduced Instruction Set Computer’.It stands for ‘Complex Instruction Set Computer’.
DefinitionThe RISC processors have a smaller set of instructions with few addressing nodes.The CISC processors have a larger set of instructions with many addressing nodes.
Memory unitIt has no memory unit and uses a separate hardware to implement instructions.It has a memory unit to implement complex instructions.
ProgramIt has a hard-wired unit of programming.It has a micro-programming unit.
DesignIt is a complex complier design.It is an easy complier design.
CalculationsThe calculations are faster and precise.The calculations are slow and precise.
DecodingDecoding of instructions is simple.Decoding of instructions is complex.
TimeExecution time is very less.Execution time is very high.
External memoryIt does not require external memory for calculations.It requires external memory for calculations.
PipeliningPipelining does function correctly.Pipelining does not function correctly.
StallingStalling is mostly reduced in processors.The processors often stall.
Code expansionCode expansion can be a problem.Code expansion is not a problem.
Disc spaceThe space is saved.The space is wasted.
ApplicationsUsed in high-end applications such as video processing, telecommunications and image processing.Used in low-end applications such as security systems, home automations, etc.

51. What is the stack overflow?


If your program tries to access beyond the limit of the available stack memory then stack overflow occurs. In other words, you can say that a stack overflow occurs if the call stack pointer exceeds the stack boundary.

If stack overflow occurs, the program can crash or you can say that segmentation fault that is the result of the stack overflow.

Course Curriculum

Enroll in Firmware Development Certification Course to Enhance Your Skills

Weekday / Weekend BatchesSee Batch Details

52. What is the cause of the stack overflow?


In the embedded application we have a little amount of stack memory as compare to the desktop application. So we have to work on embedded application very carefully either we can face the stack overflow issues that can be a cause of the application crash.

Here, I have mentioned some causes of unwanted use of the stack.

  • Improper use of the recursive function.
  • Passing to many arguments in the function.
  • Passing a structure directly into a function.
  • Nested function calls.
  • Creating a huge size local array.

53. What is the difference between the I2c and SPI communication Protocols?


In the embedded system, I2C and SPI both play an important role. Both communication protocols are the example of synchronous communication but still, both have some important differences.

The important difference between the I2C and SPI communication protocol.

I2C supports half-duplex SPI is full-duplex communication
I2C requires only two-wire for communication SPI requires three or four-wire for communication (depends on requirement)
I2C is slower SPI is faster
I2C draws more power SPI draws less power
I2C is less susceptible to noise SPI is more susceptible to noise
I2C is cheaper to implement SPI is costlier to implement than I2C
I2C work on wire and logic and it has a pull-up resistor There is no requirement of a pull-up resistor in case of the SPI
In I2C communication we get the acknowledgment bit after each byte It is not supported by the SPI communication protocol
I2C ensures that data sent is received by the slave device SPI does not verify that data is received correctly
I2C supports multi-master communication Multi-master communication is not supported by the SPI
I2C supports multiple devices on the same bus without any additional select lines (work on the basis of device address) SPI requires additional signal (slave select lines) lines to manage multiple devices on the same bus
I2C supports arbitration SPI does not support the arbitration
2C support the clock stretching SPI does not support the clock stretching
I2C is better for long-distance SPI is better for the short distance
I2C developed by NXP SPI developed by Motorola
I2C can be locked up by one device that fails to release the communication bus
I2C has some extra overhead due to start and stop bits

54. What is the difference between Asynchronous and Synchronous Communication?


There are the following differences between asynchronous and synchronous communication.

Asynchronous CommunicationSynchronous Communication
There is no common clock signal between the sender and receivers.Communication is done by a shared clock.
Sends 1 byte or character at a time.Sends data in the form of blocks or frames.
Slow as compare to synchronous communication.Fast as compare to asynchronous communication.
Overhead due to start and stop bit.Less overhead.
Ability to communicate long distance.Less as compared to asynchronous communication.
A start and stop bit used for data synchronization.A shared clock is used for data synchronization.
RS232, RS485I2C, SPI.

55. What is the difference between RS232 and RS485?


The RS232 and RS485 is an old serial interface. Both serial interfaces are the standard for data communication. This question is also very important and generally ask by an interviewer.

Some important difference between the RS232 and RS485

Line configurationSingle –endeddifferential
Numbers of devices1 transmitter 1 receiver32 transmitters 32 receivers
Mode of operationSimplex or full duplexSimplex or half duplex
Maximum cable length50 feet4000 feet
Maximum data rate20 Kbits/s10 Mbits/s
Typical logic levels+-5 ~ +-15V+-1.5 ~ +-6V
Minimum receiver input impedance3 ~ 7 K-ohm12 K-ohm
Receiver sensitivity+-3V+-200mV

56. What is the difference between Bit Rate and Baud Rate?


Bit RateBaud Rate
Bit rate is the number of bits per second.Baud rate is the number of signal units per second.
It determines the number of bits traveled per second.It determines how many times the state of a signal is changing.
Cannot determine the bandwidth.It can determine how much bandwidth is required to send the signal.
This term generally used to describe the processor efficiency.This term generally used to describe the data transmission over the channel.
Bit rate = baud rate x the number of bits per signal unitBaud rate = bit rate / the number of bits per signal unit

57. What is segmentation fault in C?


A segmentation fault is a common problem that causes programs to crash. A core file (core dumped file) also associated with a segmentation fault that is used by the developer to finding the root cause of the crashing (segmentation fault).

Generally, the segmentation fault occurs when a program tried to access a memory location that is not allowed to access or tried to access a memory location in a way that is not allowed (tried to access read-only memory).

58. What are the common causes of segmentation fault in C?


There are many reasons for the segmentation fault, here I am listing some common causes of the segmentation fault.

  1. 1. Dereferencing NULL pointers.
  2. 2. Tried to write read-only memory (such as code segment).
  3. 3. Trying to access a nonexistent memory address (outside process’s address space).
  4. 4. Trying to access memory the program does not have rights to (such as kernel structures in process context).
  5. 5. Sometimes dereferencing or assigning to an uninitialized pointer (because might point an invalid memory) can be the cause of the segmentation fault.
  6. 6. Dereferencing the freed memory (after calling the free function) can also be caused by the segmentation fault.
  7. 7. A stack overflow is also caused by the segmentation fault.
  8. 8. A buffer overflow (try to access the array beyond the boundary) is also a cause of the segmentation fault.

59. What is the difference between Segmentation fault and Bus error?


In the case of segmentation fault, SIGSEGV (11) signal is generated. Generally, a segmentation fault occurs when the program tries to access the memory to which it doesn’t have access to.

In below I have mentioned some scenarios where SIGSEGV signal is generated.

  • When trying to de-referencing a NULL pointer.
  • Trying to access memory which is already de-allocated (trying to use dangling pointers).
  • Using uninitialized pointer(wild pointer).
  • Trying to access memory that the program doesn’t own (eg. trying to access an array element out of array bounds).

In case of a BUS error, SIGBUS (10) signal is generated. The Bus error issue occurs when a program tries to access an invalid memory or unaligned memory. The bus error comes rarely as compared to the segmentation fault.

In below I have mentioned some scenarios where SIGBUS signal is generated.

  1. 1. Non-existent address.
  2. 2. Unaligned access.
  3. 3. Paging errors

60. Size of the integer depends on what?


The C standard is explained that the minimum size of the integer should be 16 bits. Some programing language is explained that the size of the integer is implementation-dependent but portable programs shouldn’t depend on it.

Primarily the size of integer depends on the type of the compiler which has written by compiler writer for the underlying processor. You can see compilers merrily changing the size of integer according to convenience and underlying architectures. So it is my recommendation to use the C99 integer data types ( uin8_t, uin16_t, uin32_t ..) in place of standard int.

61. Are integers signed or unsigned?


According to C standard, an integer data type is by default signed. So if you create an integer variable, it can store both positive and negative value.

62. What is a difference between unsigned int and signed int in C?


The signed and unsigned integer type has the same storage (according to the standard at least 16 bits) and alignment but still, there is a lot of difference them, in bellows lines, I am describing some difference between the signed and unsigned integer.

  1. 1. A signed integer can store the positive and negative value both but beside it unsigned integer can only store the positive value.
  2. 2. The range of nonnegative values of a signed integer type is a sub-range of the corresponding unsigned integer type.

For example,

Assuming the size of the integer is 2 bytes.

signed int -32768 to +32767

unsigned int 0 to 65535

  1. 1. When computing the unsigned integer, it never gets overflow because if the computation result is greater than the largest value of the unsigned integer type, it is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type.
    For example,
    Computational Result % (Largest value of the unsigned integer+1)
  2. 2. The overflow of the signed integer type is undefined.
  3. 3. If Data is signed type negative value, the right shifting operation of Data is implementation-dependent but for the unsigned type, it would be Data/ 2pos.
  4. 4. If Data is signed type negative value, the left shifting operation of Data shows the undefined behavior but for the unsigned type, it would be Data x 2pos.

63. What is the difference between a macro and a function?



64. What is the difference between typedef & Macros?


Let’s see the short description of the typedef and macro to understand the difference between them.


The C language provides a very important keyword typedef for defining a new name for existing types. The typedef is the compiler directive mainly use with user-defined data types (structure, union or enum) to reduce their complexity and increase code readability and portability.


  • typedef type NewTypeName;

 Let’s take an example,

  • typedef unsigned int UnsignedInt;

Now UnsignedInt is a new type and using it, we can create a variable of unsigned int. So in the below example, Mydata is unsigned int variable.

  • UnsignedInt Mydata;

Note: A typedef creates synonyms or a new name for existing types it does not create new types.


A macro is a pre-processor directive and it replaces the value before compiling the code. One of the major problems with the macro is that there is no type checking. Generally, the macro is used to create the alias, in C language. A macro is also used as a file guard in C and C++.



65. What do you mean by enumeration in C?


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

Basically, we used the enum to increase the code readability and with enum easy to debug the code as compared to symbolic constant (macro). The most important property of enum is that it follows the scope rule and the compiler automatically assigns the value to its member constant.

Note: A variable of enumeration type stores one of the values of the enumeration list defined by that type.

Syntax of enum,

  • enum Enumeration_Tag {
  •    Enumeration_List
  • };

The Enumeration_Tag specifies the enumeration type name.

The Enumeration_List is a comma-separated list of named constant.

66. What is the difference between const and macro?


  • The const keyword is handled by the compiler, in another hand, a macro is handled by the preprocessor directive.
  • const is a qualifier that is modified the behavior of the identifier but macro is preprocessor directive.
  • There is type checking is occurred with const keyword but does not occur with #define.
  • const is scoped by C block, #define applies to a file.
  • const can be passed as a parameter (as a pointer) to the function. In the case of call by reference, it prevents to modify the passed object value.

67.  What will be the output of the below C program?


  • #include <stdio.h>
  • int main()
  • {
  •    char var = 10;
  •    void *ptr = &var;
  •    printf(“%d %d”,*(char*)ptr,++(*(char*)ptr));
  •    return 0;
  • }

Output: undefined

Explanation: Due to the sequence point the output vary on a different platform.

68. Write a program swap two numbers without using the third variable?


Let’s assume a, b two numbers, there are a lot of methods two swap two numbers without using the third variable.

Method 1( (Using Arithmetic Operators):

  • #include <stdio.h>
  • int main()
  • {
  •    int a = 10, b = 5;
  •   // algo to swap ‘a’ and ‘b’
  •    a = a + b; // a becomes 15
  •    b = a – b; // b becomes 10
  •    a = a – b; // fonally a becomes 5
  •    printf(“After Swapping the value of: a = %d, b = %d\n\n”, a, b);
  •    return 0;
  • }

 Method 2 (Using Bitwise XOR Operator):

  • #include <stdio.h>
  • int main()
  • {
  •    int a = 10, b = 5;
  •   // algo to swap ‘a’ and ‘b’
  •    a = a ^ b; // a becomes (a ^ b)
  •    b = a ^ b; // b = (a ^ b ^ b), b becomes a
  •    a = a ^ b; // a = (a ^ b ^ a), a becomes b
  •    printf(“After Swapping the value of: a = %d, b = %d\n\n”, a, b);
  •    return 0;
  • }

69. What is meant by structure padding?


In the case of structure or union, the compiler inserts some extra bytes between the members of structure or union for the alignment, these extra unused bytes are called padding bytes and this technique is called padding.

Padding has increased the performance of the processor at the penalty of memory. In structure or union data members aligned as per the size of the highest bytes member to prevent the penalty of performance.

FirmWare Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

70. What is static memory allocation and dynamic memory allocation?


According to C standard, there are four storage duration, static, thread (C11), automatic, and allocated. The storage duration determines the lifetime of the object.

The static memory allocation:

Static Allocation means, an object has an external or internal linkage or declared with static storage-class. It’s initialized only once, prior to program startup and its lifetime is throughout the execution of the program. A global and static variable is an example of static memory allocation.

The dynamic memory allocation:

In C language, there are a lot of library functions (malloc, calloc, or realloc,..) which are used to allocate memory dynamically. One of the problems with dynamically allocated memory is that it is not destroyed by the compiler itself that means it is the responsibility of the user to deallocate the allocated memory.

When we allocate the memory using the memory management function, they return a pointer to the allocated memory block and the returned pointer is pointing to the beginning address of the memory block. If there is no space available, these functions return a null pointer.

71. What is a Function Pointer?


A function pointer is similar to the other pointers but the only difference is that it points to a function instead of a variable. In another word, we can say that a function pointer is a type of pointer that store the address of a function and these pointed function can be invoked by function pointer in a program whenever required.

72. How to declare a pointer to a function in C?


The syntax for declaring function pointer is very straightforward. It seems difficult in beginning but once you are familiar with function pointer then it becomes easy.

The declaration of a pointer to a function is similar to the declaration of a function. That means the function pointer also requires a return type, declaration name, and argument list. One thing that you need to remember here is, whenever you declare the function pointer in the program then the declaration name is preceded by the * (Asterisk) symbol and enclosed in parenthesis.

73. Where can the function pointers be used?


There are a lot of places, where the function pointers can be used. Generally, function pointers are used in the implementation of the callback function, finite state machine and to provide the feature of polymorphism in C language …etc.

74. What is the advantage of a void pointer in C?


There are following advantages of a void pointer in c.

  1. 1. Using the void pointer we can create a generic function that can take arguments of any data type. The memcpy and memmove library function are the best examples of the generic function, using these functions we can copy the data from the source to destination.
  2. 2. We know that void pointer can be converted to another data type that is the reason malloc, calloc or realloc library function return void *. Due to the void * these functions are used to allocate memory to any data type.
  3. 3. Using the void * we can create a generic linked list. For more information see this link: How to create generic Link List.

75. What are dangling pointers?


Generally, daggling pointers arise when the referencing object is deleted or deallocated, without changing the value of the pointers. It creates the problem because the pointer is still pointing the memory that is not available. When the user tries to dereference the daggling pointers than it shows the undefined behavior and can be the cause of the segmentation fault.

76. What is the meaning of the below declarations?


  1. 1. const int a;
  2. 2. int const a;
  3. 3. const int *a;
  4. 4. int * const a;
  5. 5. int const * a const;
  • The “a” is a constant integer.
  • Similar to first, “a” is a constant integer.
  • Here “a” is a pointer to a const integer, the value of the integer is not modifiable, but the pointer is not modifiable.
  • Here “a” is a const pointer to an integer, the value of the pointed integer is modifiable, but the pointer is not modifiable.
  • Here “a” is a const pointer to a const integer that means the value of pointed integer and pointer both are not modifiable.

77. What are the uses of the keyword static?


In C language, the static keyword has a lot of importance. If we have used the static keyword with a variable or function, then only internal or none linkage is worked.

 I have described some simple use of a static keyword.

  1. 1. A static variable only initializes once, so a variable declared static within the body of a function maintains its prior value between function invocations.
  2. 2. A global variable with a static keyword has internal linkage, so it only accesses within the translation unit (.c). It is not accessible by another translation unit. The static keyword protects your variable to access from another translation unit.
  3. 3. By default in C language, the linkage of the function is external that it means it is accessible by the same or another translation unit. With the help of the static keyword, we can make the scope of the function local, it only accesses by the translation unit within it is declared.

78. What is the difference between pass by value by reference in c and pass by reference in c?


Pass By Value:

  • In this method, the value of the variable is passed. Changes made to formal will not affect the actual parameters.
  • Different memory locations will be created for both variables.
  • Here there will be a temporary variable created in the function stack which does not affect the original variable.

Pass By Reference :

  • In Pass by reference, an address of the variable is passed to a function.
  • Whatever changes made to the formal parameter will affect the value of actual parameters(a variable whose address is passed).
  • Both formal and actual parameters shared the same memory location.
  • it is useful when you required to returns more than 1 value.

79. What is a reentrant function?


In computing, a computer program or subroutine is called reentrant if it can be interrupted in the middle of its execution and then safely be called again (“re-entered”) before its previous invocations complete execution. The interruption could be caused by an internal action such as a jump or call, or by an external action such as an interrupt or signal. Once the reentered invocation completes, the previous invocations will resume correct execution.

80. What is the inline function?


An inline keyword is a compiler directive that only suggests the compiler to substitute the body of the function at the calling the place. It is an optimization technique used by the compilers to reduce the overhead of function calls.

Are you looking training with Right Jobs?

Contact Us

Popular Courses