0% found this document useful (0 votes)
23 views13 pages

Answers

Uploaded by

Jayanth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views13 pages

Answers

Uploaded by

Jayanth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Certainly!

Below is a consolidated document containing all the generated answers


from our conversation, formatted for clarity.

---

# C Programming Questions and Answers

## Important Questions

### 1. What is Interrupt?


**Answer:** An interrupt is a signal to the processor emitted by hardware or
software indicating an event that needs immediate attention. It allows the CPU to
stop its current activities and execute a special routine called an interrupt
handler.

### 2. What is ISR?


**Answer:** An ISR (Interrupt Service Routine) is a special function that is
executed in response to an interrupt. It handles the interrupt and performs the
necessary actions to address the event that triggered the interrupt.

### 3. What is Startup Code?


**Answer:** Startup code is the initial code that runs before the main function in
a C program. It typically sets up the environment, initializes global variables,
and prepares the system for execution.

### 4. What is Interrupt Latency?


**Answer:** Interrupt latency is the time taken from the moment an interrupt is
generated to the moment the corresponding ISR begins execution. It includes the
time taken to complete the current instruction, save the context, and switch to the
ISR.

### 5. What is Volatile keyword? Uses


**Answer:** The `volatile` keyword is used in C to indicate that a variable's value
may change unexpectedly, such as when it is modified by an ISR or hardware. It
prevents the compiler from optimizing accesses to the variable, ensuring that the
most recent value is always read.

### 6. What is Void pointer?


**Answer:** A void pointer is a pointer that does not have a specific data type
associated with it. It can point to any data type, but it must be cast to a
specific type before dereferencing.

### 7. What is Null pointer?


**Answer:** A null pointer is a pointer that does not point to any valid memory
location. It is often used to indicate that the pointer is not initialized or that
it is not currently pointing to a valid object.

### 8. What is Wild pointer?


**Answer:** A wild pointer is a pointer that has not been initialized to a valid
memory address. Dereferencing a wild pointer can lead to undefined behavior and
program crashes.

### 9. What is Dangling pointer?


**Answer:** A dangling pointer is a pointer that points to a memory location that
has been freed or deallocated. Accessing a dangling pointer can lead to undefined
behavior.

### 10. What is Macro?


**Answer:** A macro is a preprocessor directive that defines a piece of code that
can be reused throughout the program. Macros are expanded inline during
preprocessing, allowing for code substitution without the overhead of function
calls.

### 11. What is Constant?


**Answer:** A constant is a fixed value that cannot be altered during the execution
of a program. Constants can be defined using the `const` keyword or using
preprocessor directives.

### 12. What is Reentrant Function?


**Answer:** A reentrant function is a function that can be interrupted in the
middle of its execution and safely called again ("re-entered") before the previous
executions are complete. Reentrant functions do not rely on static or global
variables.

### 13. What is Segmentation Fault? Reason for it?


**Answer:** A segmentation fault is a specific kind of error caused by accessing
memory that the program is not allowed to access. Common reasons include
dereferencing null or uninitialized pointers, accessing out-of-bounds array
elements, or writing to read-only memory.

### 14. What is Virtual Memory?


**Answer:** Virtual memory is a memory management technique that provides an
"idealized abstraction" of the storage resources that are actually available on a
computer. It allows a program to use more memory than is physically available by
using disk space as an extension of RAM.

### 15. What is Memory Leak?


**Answer:** A memory leak occurs when a program allocates memory on the heap but
fails to release it back to the operating system after it is no longer needed. This
can lead to increased memory usage over time and can eventually exhaust the
available memory.

### 16. What is Static Variable?


**Answer:** A static variable in C is a variable that retains its value between
function calls. It is initialized only once and exists for the lifetime of the
program.

### 17. What is Function pointer?


**Answer:** A function pointer is a pointer that points to a function instead of a
data value. Function pointers can be used to call functions dynamically, pass
functions as arguments to other functions, or implement callback functions.

### 18. What is Pointer to Array?


**Answer:** A pointer to an array is a pointer that points to the first element of
an array. It allows for array manipulation and can be used to pass arrays to
functions efficiently.

### 19. What is Inline Function?


**Answer:** An inline function is a function that is expanded in line when it is
called, rather than being invoked through the usual function call mechanism. This
can improve performance by eliminating the overhead of function calls, especially
for small functions.

### 20. What is Memory Fragmentation?


**Answer:** Memory fragmentation occurs when free memory is split into small, non-
contiguous blocks over time, making it difficult to allocate larger blocks of
memory even when the total free memory is sufficient.
### 21. What is Pass by Value & Pass by Reference?
**Answer:** Pass by value means that a copy of the variable is passed to the
function, so changes made to the parameter inside the function do not affect the
original variable. Pass by reference means that a reference (or pointer) to the
variable is passed, allowing the function to modify the original variable.

### 22. What is Semaphore & types of it?


**Answer:** A semaphore is a synchronization primitive used to control access to a
common resource in a concurrent system. Semaphores can be classified into two
types: binary semaphores (or mutexes) and counting semaphores.

### 23. What is Recursive Function?


**Answer:** A recursive function is a function that calls itself in order to solve
a problem. Recursive functions typically have a base case that stops the recursion
and a recursive case that breaks the problem into smaller subproblems.

### 24. What is Forward Referencing?


**Answer:** Forward referencing occurs when a variable or function is used before
it is declared or defined in the code. In C, this is allowed for functions but not
for variables.

### 25. What are Little & Big Endian?


**Answer:** Little-endian and big-endian are two ways of storing multibyte data
types (like integers) in memory. Little-endian stores the least significant byte at
the lowest memory address, while big-endian stores the most significant byte at the
lowest memory address.

### 26. What is Endian?


**Answer:** Endianness refers to the order in which bytes are arranged within
larger data types (like integers) in computer memory. It determines how data is
read and written in memory.

### 27. Scope of function that is declared as Static?


**Answer:** A function declared as `static` in C has internal linkage, meaning it
is only visible within the file in which it is defined. This prevents name clashes
with functions in other files and encapsulates the function's implementation.

### 28. Can a pointer be volatile?


**Answer:** Yes, a pointer can be declared as `volatile`. This means that the
pointer itself can point to a memory location that may change unexpectedly, such as
hardware registers or variables modified by an ISR.

### 29. Can a volatile be const?


**Answer:** Yes, a variable can be declared as `const volatile`. This means that
the variable's value can change unexpectedly (volatile), but the program cannot
modify it directly (const).

### 30. How are Local & Global variables allocated by compiler?
**Answer:** Local variables are typically allocated on the stack, while global
variables are allocated in a fixed area of memory (the data segment) that persists
for the lifetime of the program.

### 31. Scope of Static variables?


**Answer:** Static variables have a scope limited to the block in which they are
defined, but they retain their value between function calls. If a static variable
is defined inside a function, it is initialized only once and exists for the
lifetime of the program.
### 32. What happens when recursive functions are declared Inline?
**Answer:** When a recursive function is declared as `inline`, the compiler may
attempt to expand the function inline at the call site. However, since the function
calls itself, this can lead to an infinite expansion, which is generally not
practical.

### 33. What is Watchdog Timer?


**Answer:** A watchdog timer is a hardware timer that is used to detect and recover
from computer malfunctions. If the main program fails to reset the watchdog timer
within a specified time period, the timer will expire and trigger a system reset or
an interrupt.

### 34. What is DMA?


**Answer:** Direct Memory Access (DMA) is a feature that allows certain hardware
subsystems to access the main system memory independently of the CPU. This is used
to transfer data between memory and peripherals without involving the CPU.

### 35. What is a Thread?


**Answer:** A thread is the smallest unit of processing that can be scheduled by an
operating system. Threads within the same process share the same memory space but
can execute independently.

### 36. What is a Deadlock?


**Answer:** A deadlock is a situation in a multi-threaded environment where two or
more threads are unable to proceed because each is waiting for the other to release
a resource.

### 37. What is a Race Condition?


**Answer:** A race condition occurs when two or more threads access shared data and
try to change it at the same time. If the access is not synchronized, the final
outcome depends on the timing of the threads.

### 38. What is a Signal in C?


**Answer:** A signal is a limited form of inter-process communication used in Unix-
like operating systems. It allows one process to send notifications to another
process or to itself.

### 39. What is a Thread Pool?


**Answer:** A thread pool is a collection of pre-initialized threads that can be
reused to perform multiple tasks. Instead of creating and destroying threads for
each task, a thread pool allows for efficient management of threads.

### 40. What is a Barrier in C?


**Answer:** A barrier is a synchronization mechanism that allows multiple threads
to wait until a certain number of threads have reached a specific point in their
execution.

### 41. What is a Preprocessor Directive?


**Answer:** A preprocessor directive is a command that is processed by the
preprocessor before the actual compilation of the code begins. These directives are
used to include files, define macros, and conditionally compile code.

### 42. What is a Header File?


**Answer:** A header file is a file containing C declarations and macro definitions
to be shared between several source files. Header files typically have a `.h`
extension and are included in source files using the `#include` directive.

### 43. What is a Struct?


**Answer:** A struct (short for structure) is a user-defined data type in C that
allows grouping of different data types under a single name. Structs are used to
represent a record or a complex data type.

### 44. What is a Union?


**Answer:** A union is a user-defined data type in C that allows storing different
data types in the same memory location. Unlike structs, a union can only hold one
of its non-static data members at a time.

### 45. What is the difference between Struct and Union?


**Answer:** The main differences between structs and unions in C are:
- **Memory Allocation:** A struct allocates enough memory to hold all its members,
while a union allocates enough memory to hold the largest member only.
- **Data Storage:** In a struct, all members can hold values simultaneously, while
in a union, only one member can hold a value at any given time.

### 46. How to Define a Structure with Bit Field Members?


**Answer:** A bit field is a set of adjacent bits within a single byte or word that
can be used to represent a value. Bit-fields allow for the efficient use of memory
by packing multiple values into a single data structure.

### 47. What is Context Switching?


**Answer:** Context switching is the process of storing the state of a currently
running thread or process so that it can be resumed later. This allows multiple
threads or processes to share a single CPU, enabling multitasking.

### 48. What is Paging?


**Answer:** Paging is a memory management scheme that eliminates the need for
contiguous allocation of physical memory and thus eliminates the problems of
fitting varying sized memory chunks onto the backing store.

### 49. What is a Memory Pool?


**Answer:** A memory pool is a memory management technique that pre-allocates a
block of memory for use by a program. Instead of allocating and deallocating memory
dynamically, which can be costly in terms of performance, a memory pool allows for
faster allocation and deallocation of fixed-size blocks of memory.

### 50. What is Mutex?


**Answer:** A mutex (mutual exclusion) is a synchronization primitive used to
prevent multiple threads from accessing a shared resource simultaneously. It
ensures that only one thread can lock the mutex at a time.

### 51. What is Semaphore?


**Answer:** A semaphore is a synchronization primitive that is used to control
access to a common resource in a concurrent system. Semaphores can be classified
into two types: binary semaphores (or mutexes) and counting semaphores.

### 52. Difference between Mutex & Semaphore?


**Answer:**
- **Mutex:** Used for mutual exclusion to protect shared resources. Only one thread
can lock a mutex at a time.
- **Semaphore:** Can be used for signaling between tasks and managing resource
pools. Can allow multiple threads to access a resource.

### 53. When to use Mutex & Semaphore?


**Answer:**
- **Use Mutex:** When you need to protect a shared resource from concurrent access
by multiple threads.
- **Use Semaphore:** When you need to manage access to a resource pool or signal
between tasks.
### 54. What is Soft & Hard Real-Time?
**Answer:**
- **Hard Real-Time:** Systems that must meet strict timing constraints. Missing a
deadline can lead to catastrophic failures.
- **Soft Real-Time:** Systems that can tolerate some deadline misses without severe
consequences.

### 55. What are Deadlock Causes, and How to Avoid Them?
**Answer:** Deadlocks occur when two or more tasks are waiting for each other to
release resources. Common causes include mutual exclusion, hold and wait, no
preemption, and circular wait. To avoid deadlocks, use resource hierarchy,
implement timeout mechanisms, and use a resource allocation graph.

### 56. What is Interprocess Communication?


**Answer:** Interprocess communication (IPC) refers to the mechanisms that allow
processes to communicate and synchronize their actions. IPC is essential in multi-
process systems to share data and coordinate tasks.

### 57. What is Message Queue?


**Answer:** A message queue is a communication mechanism that allows processes or
threads to send and receive messages in a synchronized manner. It provides a way to
exchange data between tasks without direct access to each other's memory space.

### 58. What is Binary & Counting Semaphore?


**Answer:**
- **Binary Semaphore:** A semaphore that can take only two values (0 and 1). It is
used to manage access to a single resource.
- **Counting Semaphore:** A semaphore that can take non-negative integer values. It
is used to manage access to a resource pool with multiple instances.

### 59. Execution process of a C program?


**Answer:** The execution process of a C program typically involves several stages:
preprocessing, compilation, assembly, linking, loading, and execution.

### 60. Difference between Static Memory Allocation & DMA?


**Answer:** Static memory allocation occurs at compile time and remains fixed,
while dynamic memory allocation (DMA) occurs at runtime and can be adjusted as
needed.

### 61. What is Compiling, Linking & Loading?


**Answer:** Compiling translates source code into machine code, linking combines
object files into an executable, and loading prepares the executable for execution
in memory.

### 62. Explain C Memory Layout?


**Answer:** The memory layout of a C program typically consists of several
segments: text segment (code), data segment (initialized global/static variables),
BSS segment (uninitialized global/static variables), heap segment (dynamic memory),
and stack segment (function calls, local variables).

### 63. Pointer to Array & Array of Pointers?


**Answer:** A pointer to an array points to the first element of the array, while
an array of pointers is an array where each element is a pointer.

### 64. What is Bit-field?


**Answer:** A bit-field is a set of adjacent bits within a single byte or word that
can be used to represent a value, allowing for efficient use of memory.
### 65. What is ADC?
**Answer:** ADC (Analog-to-Digital Converter) is a device that converts an analog
signal into a digital signal.

### 66. What is DAC?


**Answer:** DAC (Digital-to-Analog Converter) is a device that converts a digital
signal into an analog signal.

### 67. What is Typecasting?


**Answer:** Typecasting is the process of converting a variable from one data type
to another, either explicitly or implicitly.

### 68. What is Non-volatile Memory in C?


**Answer:** Non-volatile memory retains its data even when the power is turned off,
commonly used for storing firmware and configuration settings.

### 69. Difference between Compiler & Interpreter?


**Answer:** A compiler translates the entire source code into machine code before
execution, while an interpreter translates source code line by line during
execution.

### 70. What are Pre-defined Macros?


**Answer:** Pre-defined macros are automatically defined by the compiler and
provide information about the compilation environment, such as `__DATE__`,
`__TIME__`, `__FILE__`, and `__LINE__`.

### 71. What is an RTOS?


**Answer:** An RTOS (Real-Time Operating System) is an operating system designed to
manage hardware resources and execute tasks within strict timing constraints.

### 72. What are the Key Features of RTOS?


**Answer:** Key features of an RTOS include deterministic behavior, task
scheduling, inter-task communication, resource management, and minimal latency.

### 73. What are the General Purposes of RTOS?


**Answer:** The general purposes of an RTOS include real-time processing, task
management, resource sharing, event handling, and system reliability.

### 74. What are the Tasks in RTOS?


**Answer:** Tasks in an RTOS are independent units of execution that perform
specific functions, which can be periodic or aperiodic.

### 75. What is the Role of Time Tick in an RTOS?


**Answer:** The time tick in an RTOS is a periodic interrupt generated by a timer,
used to manage task scheduling, time slicing, and timeouts.

### 76. What is the Importance of Task Allocation in RTOS?


**Answer:** Task allocation is crucial for ensuring efficient resource usage and
that tasks meet their timing requirements.

### 77. What is Synchronization in RTOS?


**Answer:** Synchronization refers to the coordination of tasks to ensure correct
operation when accessing shared resources, preventing race conditions.

### 78. What is Context Switching? How does it occur in RTOS?


**Answer:** Context switching is the process of saving the state of a currently
running task and restoring the state of the next task to be executed, allowing
multiple tasks to share the CPU.
### 79. Different Scheduling Algorithms used in RTOS?
**Answer:** Common scheduling algorithms include Rate Monotonic Scheduling (RMS),
Earliest Deadline First (EDF), Round Robin, and Priority Inheritance.

### 80. Explain Preemption & Priority Inversion?


**Answer:** Preemption allows a higher-priority task to interrupt a currently
running task, while priority inversion occurs when a lower-priority task holds a
resource needed by a higher-priority task.

### 81. What is Inter-task Communication?


**Answer:** Inter-task communication refers to the mechanisms that allow tasks in
an RTOS to exchange data and synchronize their actions.

### 82. How does Memory Management work in RTOS?


**Answer:** Memory management involves allocating and deallocating memory for
tasks, managing memory pools, and ensuring efficient memory usage.

### 83. Advantages & Disadvantages of using RTOS?


**Answer:**
**Advantages:** Deterministic behavior, efficient task management, resource
sharing, real-time performance.
**Disadvantages:** Complexity, overhead, cost.

### 84. How does RTOS handle interrupts?


**Answer:** An RTOS handles interrupts by executing an ISR in response to hardware
events, saving the context of the current task and restoring the context of the
next task.

### 85. What is the Role of Timer Tick in an RTOS?


**Answer:** The timer tick is used to manage task scheduling, time slicing, and
timeouts.

### 86. How do you handle Resource Sharing and Mutual Exclusion in an RTOS?
**Answer:** Resource sharing and mutual exclusion are handled using synchronization
mechanisms such as mutexes, semaphores, and critical sections.

### 87. Importance of Stack Allocation in RTOS?


**Answer:** Stack allocation is important for managing local variables, function
calls, and control flow, ensuring independent execution of tasks.

### 88. What is Memory Pool? How is it used in RTOS?


**Answer:** A memory pool is a pre-allocated block of memory divided into fixed-
size blocks for use by tasks, allowing efficient allocation and deallocation.

### 89. What is Mutex?


**Answer:** A mutex is a synchronization primitive used to prevent multiple threads
from accessing a shared resource simultaneously.

### 90. What is Semaphore?


**Answer:** A semaphore is a synchronization primitive used to control access to a
common resource in a concurrent system.

### 91. Difference between Mutex & Semaphore?


**Answer:** Mutex is used for mutual exclusion, while semaphore can be used for
signaling and managing resource pools.

### 92. When to use Mutex & Semaphore?


**Answer:** Use mutex for protecting shared resources and semaphore for managing
resource pools or signaling.
### 93. What is Soft & Hard Real-Time?
**Answer:** Hard real-time systems must meet strict timing constraints, while soft
real-time systems can tolerate some deadline misses.

### 94. What are Deadlock Causes, and How to Avoid Them?
**Answer:** Deadlocks occur due to mutual exclusion, hold and wait, no preemption,
and circular wait. To avoid them, use resource hierarchy and implement timeout
mechanisms.

### 95. What is Interprocess Communication?


**Answer:** IPC refers to mechanisms that allow processes to communicate and
synchronize their actions.

### 96. What is Message Queue?


**Answer:** A message queue is a communication mechanism that allows processes or
threads to send and receive messages in a synchronized manner.

### 97. What is Binary & Counting Semaphore?


**Answer:** Binary semaphore can take values 0 and 1, while counting semaphore can
take non-negative integer values.

### 98. Execution process of a C program?


**Answer:** The execution process involves preprocessing, compilation, assembly,
linking, loading, and execution.

### 99. Difference between Static Memory Allocation & DMA?


**Answer:** Static memory allocation occurs at compile time, while dynamic memory
allocation (DMA) occurs at runtime.

### 100. What is Compiling, Linking & Loading?


**Answer:** Compiling translates source code into machine code, linking combines
object files into an executable, and loading prepares the executable for execution
in memory.

### 101. Explain C Memory Layout?


**Answer:** The memory layout consists of text segment (code), data segment
(initialized global/static variables), BSS segment (uninitialized global/static
variables), heap segment (dynamic memory), and stack segment (function calls, local
variables).

### 102. Pointer to Array & Array of Pointers?


**Answer:** A pointer to an array points to the first element, while an array of
pointers is an array where each element is a pointer.

### 103. What is Bit-field?


**Answer:** A bit-field is a set of adjacent bits within a single byte or word that
can be used to represent a value.

### 104. What is ADC?


**Answer:** ADC (Analog-to-Digital Converter) converts an analog signal into a
digital signal.

### 105. What is DAC?


**Answer:** DAC (Digital-to-Analog Converter) converts a digital signal into an
analog signal.

### 106. What is Typecasting?


**Answer:** Typecasting is the process of converting a variable from one data type
to another.

### 107. What is Non-volatile Memory in C?


**Answer:** Non-volatile memory retains its data even when the power is turned off.

### 108. Difference between Compiler & Interpreter?


**Answer:** A compiler translates the entire source code into machine code before
execution, while an interpreter translates source code line by line during
execution.

### 109. What are Pre-defined Macros?


**Answer:** Pre-defined macros are automatically defined by the compiler and
provide information about the compilation environment.

### 110. What is an RTOS?


**Answer:** An RTOS (Real-Time Operating System) is designed to manage hardware
resources and execute tasks within strict timing constraints.

### 111. What are the Key Features of RTOS?


**Answer:** Key features include deterministic behavior, task scheduling, inter-
task communication, resource management, and minimal latency.

### 112. What are the General Purposes of RTOS?


**Answer:** General purposes include real-time processing, task management,
resource sharing, event handling, and system reliability.

### 113. What are the Tasks in RTOS?


**Answer:** Tasks are independent units of execution that perform specific
functions, which can be periodic or aperiodic.

### 114. What is the Role of Time Tick in an RTOS?


**Answer:** The time tick is used to manage task scheduling, time slicing, and
timeouts.

### 115. What is the Importance of Task Allocation in RTOS?


**Answer:** Task allocation is crucial for ensuring efficient resource usage and
that tasks meet their timing requirements.

### 116. What is Synchronization in RTOS?


**Answer:** Synchronization refers to the coordination of tasks to ensure correct
operation when accessing shared resources.

### 117. What is Context Switching? How does it occur in RTOS?


**Answer:** Context switching is the process of saving the state of a currently
running task and restoring the state of the next task to be executed.

### 118. Different Scheduling Algorithms used in RTOS?


**Answer:** Common scheduling algorithms include Rate Monotonic Scheduling (RMS),
Earliest Deadline First (EDF), Round Robin, and Priority Inheritance.

### 119. Explain Preemption & Priority Inversion?


**Answer:** Preemption allows a higher-priority task to interrupt a currently
running task, while priority inversion occurs when a lower-priority task holds a
resource needed by a higher-priority task.

### 120. What is Inter-task Communication?


**Answer:** Inter-task communication refers to the mechanisms that allow tasks in
an RTOS to exchange data and synchronize their actions.
### 121. How does Memory Management work in RTOS?
**Answer:** Memory management involves allocating and deallocating memory for
tasks, managing memory pools, and ensuring efficient memory usage.

### 122. Advantages & Disadvantages of using RTOS?


**Answer:**
**Advantages:** Deterministic behavior, efficient task management, resource
sharing, real-time performance.
**Disadvantages:** Complexity, overhead, cost.

### 123. How does RTOS handle interrupts?


**Answer:** An RTOS handles interrupts by executing an ISR in response to hardware
events.

### 124. What is the Role of Timer Tick in an RTOS?


**Answer:** The timer tick is used to manage task scheduling, time slicing, and
timeouts.

### 125. How do you handle Resource Sharing and Mutual Exclusion in an RTOS?
**Answer:** Resource sharing and mutual exclusion are handled using synchronization
mechanisms such as mutexes, semaphores, and critical sections.

### 126. Importance of Stack Allocation in RTOS?


**Answer:** Stack allocation is important for managing local variables, function
calls, and control flow.

### 127. What is Memory Pool? How is it used in RTOS?


**Answer:** A memory pool is a pre-allocated block of memory divided into fixed-
size blocks for use by tasks.

### 128. What is Mutex?


**Answer:** A mutex is a synchronization primitive used to prevent multiple threads
from accessing a shared resource simultaneously.

### 129. What is Semaphore?


**Answer:** A semaphore is a synchronization primitive used to control access to a
common resource in a concurrent system.

### 130. Difference between Mutex & Semaphore?


**Answer:** Mutex is used for mutual exclusion, while semaphore can be used for
signaling and managing resource pools.

### 131. When to use Mutex & Semaphore?


**Answer:** Use mutex for protecting shared resources and semaphore for managing
resource pools or signaling.

### 132. What is Soft & Hard Real-Time?


**Answer:** Hard real-time systems must meet strict timing constraints, while soft
real-time systems can tolerate some deadline misses.

### 133. What are Deadlock Causes, and How to Avoid Them?
**Answer:** Deadlocks occur due to mutual exclusion, hold and wait, no preemption,
and circular wait. To avoid them, use resource hierarchy and implement timeout
mechanisms.

### 134. What is Interprocess Communication?


**Answer:** IPC refers to mechanisms that allow processes to communicate and
synchronize their actions.
### 135. What is Message Queue?
**Answer:** A message queue is a communication mechanism that allows processes or
threads to send and receive messages in a synchronized manner.

### 136. What is Binary & Counting Semaphore?


**Answer:** Binary semaphore can take values 0 and 1, while counting semaphore can
take non-negative integer values.

### 137. Execution process of a C program?


**Answer:** The execution process involves preprocessing, compilation, assembly,
linking, loading, and execution.

### 138. Difference between Static Memory Allocation & DMA?


**Answer:** Static memory allocation occurs at compile time, while dynamic memory
allocation (DMA) occurs at runtime.

### 139. What is Compiling, Linking & Loading?


**Answer:** Compiling translates source code into machine code, linking combines
object files into an executable, and loading prepares the executable for execution
in memory.

### 140. Explain C Memory Layout?


**Answer:** The memory layout consists of text segment (code), data segment
(initialized global/static variables), BSS segment (uninitialized global/static
variables), heap segment (dynamic memory), and stack segment (function calls, local
variables).

### 141. Pointer to Array & Array of Pointers?


**Answer:** A pointer to an array points to the first element, while an array of
pointers is an array where each element is a pointer.

### 142. What is Bit-field?


**Answer:** A bit-field is a set of adjacent bits within a single byte or word that
can be used to represent a value.

### 143. What is ADC?


**Answer:** ADC (Analog-to-Digital Converter) converts an analog signal into a
digital signal.

### 144. What is DAC?


**Answer:** DAC (Digital-to-Analog Converter) converts a digital signal into an
analog signal.

### 145. What is Typecasting?


**Answer:** Typecasting is the process of converting a variable from one data type
to another.

### 146. What is Non-volatile Memory in C?


**Answer:** Non-volatile memory retains its data even when the power is turned off.

### 147. Difference between Compiler & Interpreter?


**Answer:** A compiler translates the entire source code into machine code before
execution, while an interpreter translates source code line by line during
execution.

### 148. What are Pre-defined Macros?


**Answer:** Pre-defined macros are automatically defined by the compiler and
provide information about the compilation environment.
### 149. What is an RTOS?
**Answer:** An RTOS (Real-Time Operating System) is designed to manage hardware
resources and execute tasks within strict timing constraints.

### 150. What are the Key Features of RTOS?


**Answer:** Key features include deterministic behavior, task scheduling, inter-
task communication, resource management, and minimal latency.

### 151. What are the General Purposes of RTOS?


**Answer:** General purposes include real-time processing, task management,
resource sharing, event handling, and system reliability.

### 152. What are the Tasks in RTOS?


**Answer:** Tasks are independent units of execution that perform specific
functions.

### 153. What is the Role of Time Tick in an RTOS?


**Answer:** The time tick is used to manage task scheduling, time slicing, and
timeouts.

### 154. What is the Importance of Task Allocation in RTOS?


**Answer:** Task allocation is crucial for ensuring efficient resource usage and
that tasks meet their timing requirements.

### 155. What is Synchronization in RTOS?


**Answer:** Synchronization refers to the coordination of tasks to ensure correct
operation when accessing shared resources.

### 156. What is Context Switching? How does it occur in RTOS?


**Answer:** Context switching is the process of saving the state of a currently
running task and restoring the state of the next task to be executed.

### 157. Different Scheduling Algorithms used in RTOS?


**Answer:** Common scheduling algorithms include Rate Monotonic Scheduling (RMS),
Earliest Deadline First (EDF), Round Robin, and Priority Inheritance.

### 158. Explain Preemption & Priority Inversion?


**Answer:** Preemption allows a higher-priority task to interrupt a currently
running task, while priority inversion occurs when a lower-priority task holds a
resource needed by a higher-priority task.

### 159. What is Inter-task Communication?


**Answer:** Inter-task communication refers to the mechanisms that allow tasks in
an RTOS to exchange data and synchronize their actions.

### 160. How does Memory Management work in RTOS?


**Answer:** Memory management involves allocating and deallocating memory for
tasks, managing memory pools, and ensuring efficient memory usage.

You might also like