I remember getting my first “Embedded Interview” after countless hours of CV editing, formatting and writing customized cover letters while applying to Job portals and startup websites. It was exciting all nevertheless the pressure to ace my interview got me wishing if I could read Minds like Xavier!!!
Though, wishful thinking didn’t help me at all!!!
What really helped me were a compilation of my university scrapbooks and online blogs to get my technical basics right, so this post is about list of questions which might help individuals whether freshers or little seasoned Engineers who are preparing for their Interviews.
I hope these embedded system interview questions and answer will be helpful to you. If you have any other important questions related to the embedded systems and concepts or have better answers, then please write in the comment box. I will make sure to add edits.
Content
- Embedded C Interview Questions for Freshers.
- What are the components of an Embedded system?
- Difference Between RISC and CISC Processor?
- Difference between Von-Neuman and Harvard Architecture?
- Difference between BJT and MOSFET?
- Difference Between Microcontroller and Microprocessor?
- What is the Difference between Oscillator and Crystal Oscillator?
- What are the different types of Buses used by Embedded Systems?
- What is the boot-loader?
- Difference between UART, SPI and I2C?
- List various timers in embedded systems?
- Explain what is a Watchdog Timer?
- What is the need of pull up and pull down resistor in circuit?
- Embedded C Programming Interview Questions.
- Difference between C and Embedded C?
- Difference between compiler and interpreter?
- Difference between while(1) and while(0) in C language?
- Difference Between Structure and Array in C?
- Difference Between Structure and Union in C?
- Explain What Are The Different Storage Classes In C?
- Explain What Are The Different Qualifiers In C?
- What Is Pass By Value And Pass By Reference?
- Which statement is faster ++I or i+1?
- Embedded C Interview Questions for Experienced Engineers.
- What do you understand by startup code?
- Functions of Startup file?
- What are the differences between process and thread?
- What is ISR?
- Role of Interrupt Vector Table in Interrupt Processing?
- Explain What Is Interrupt Latency? How Can We Reduce It?
- What are the uses of the Keyword Static?
- What does “const int x;” mean?
- Where are constant variables stored in memory?
- How can you protect a character pointer by some accidental modification with the pointer address?
- Can a variable be volatile and const both?
- What is a Null pointer?
- What is the size of a pointer?
- When does a segmentation fault occur?
- What Is Difference Between Using A Macro And Inline Function?
- How can you use a variable in a source file defined in another source file?
- Little and Big Endian Mystery
- List the 4 levels of testing in Embedded Systems.
- What is multithreading and multiprocessing?
- What is Mutex?
- What is Semaphore?
- What are the 2 types of Semaphore?
- Is there any difference between Deadlock and Starvation?
- Difference between RS232 and RS485 (RS232 vs RS485)?
- What is CAN?
- Why CAN?
- Standard CAN vs Extended CAN
- How do CAN bus modules communicate?
- Why Can Is Having 120 Ohms At Each End?
Embedded C Interview Questions for Freshers
1.1 What are the components of an Embedded System?
As the embedded system is made up of hardware and software components. In below section hardware components are described below:
- Power supply
- Processor
- Memory
- Timers counters
- Communication ports
- Output and Input
- Circuits used in application
When all the hardware components are selected for an embedded system the next task is to select software components for designing an embedded system.
- Assembler
- Emulator
- Debugger
- IDE and Compiler
1.2 Difference Between RISC and CISC Processor?
The Major Difference Between RISC and CISC is that RISC and CISC are the computer instruction sets which is a part of computer architecture. The Key Difference Between RISC and CISC is in the number of computing cycles each of their instructions take.
Basis of Comparison | RISC | CISC |
---|---|---|
Acronym | RISC stands for Reduced Instruction Set Computer | CISC stands for Complex Instruction Set Computer |
Definition | RISC processors have simple instructions taking about one clock cycle. The average Clock cycles Per Instruction(CPI) of a RISC processor is 1.5 | CISC processors have complex instructions that take up multiple clock cycles for execution. The average Clock cycles Per Instruction of a CISC processor is between 2 and 15 |
Memory unit | There are hardly any instructions that refer memory. | Most of the instructions refer memory |
RISC processors have a fixed instruction format | CISC processors have variable instruction format. | |
The instruction set is reduced i.e. it has only few instructions in the instruction set. Many of these instructions are very primitive. | The instruction set has a variety of different instructions that can be used for complex operations. | |
RISC has fewer addressing modes and most of the instructions in the instruction set have register to register addressing mode. | CISC has many different addressing modes and can thus be used to represent higher level programming language statements more efficiently. | |
Complex addressing modes are synthesized using software. | CISC already supports complex addressing modes | |
Multiple register sets are present | Only has a single register set | |
Pipelining | RISC processors are highly pipelined | They are normally not pipelined or less pipelined |
The complexity of RISC lies in the compiler that executes the program. | The complexity lies in the micro program | |
Applications | The most common RISC microprocessors are Alpha, ARC, ARM, AVR, MIPS, PA-RISC, PIC, Power Architecture, and SPARC. | Examples of CISC processors are the System/360, VAX, PDP-11, Motorola 68000 family, AMD and Intel x86 CPUs. |
1.3 Difference between Von-Neuman and Harvard Architecture?
Basis of Comparison | Von Neumann | Harvard Architecture |
---|---|---|
Definition | The Von Neumann architecture is a style of computer architecture that is straightforward and makes use of a single memory connection. | The Harvard Architecture is the current design standard, and it features RAM and ROM that are kept completely independent. |
Design | The layout is straightforward and makes use of the same path to both store data and take instructions. | When compared to the Von Neumann architecture, this design is more complicated because it utilizes separate connections for RAM and ROM. |
Hardware | When compared to Harvard Architecture, the hardware requirements are significantly lower. | When compared to the Von Neumann Architecture, the Harvard Architecture places a greater emphasis on the use of hardware. |
Speed | In comparison to the Harvard Architecture, the speeds of the processors are significantly lower. | Harvard Architecture is faster than the others. A computer modelled are significantly lower. after the Harvard Architecture calls for an increase in the available space. |
Physical space | When compared to the Harvard Architecture computers, the Von Neumann computers have a smaller footprint in terms of the required amount of physical space. | In Harvard Architecture, the requirement for the actual space is increased. |
Internal memory | Because the memory and the programmes share the same space, there is no unused space in the internal memory. | Because the instruction memory and the data memory cannot share the same space, some of Harvard’s internal memory is going to waste somewhere. |
Running Instructions | The instructions for running can either be taken from the programme that has been stored or they can be given explicitly. As a result, the two cannot be considered together. | Due to the fact that the input and the programme instructions that are stored in the programme are taken simultaneously, the running instructions are somewhat complicated and somewhat slow. |
1.4 Difference between BJT and MOSFET?
Parameter | BJT | MOSFET |
---|---|---|
Full form | BJT stands for Bipolar Junction Transistor. | MOSFET stands for Metal Oxide Semiconductor Field Effect Transistor. |
Definition | BJT is a three-terminal semiconductor device used for switching and amplification of signals. | MOSFET is a four-terminal semiconductor device which is used for switching applications. |
Types | Based on the construction, BJTs are classified into two types: NPN and PNP. | Based on the construction and operation, the MOSFETs are classified into four types: P-channel enhancement MOSFET, N-channel enhancement MOSFET, P-channel depletion MOSFET and N-channel depletion MOSFET. |
Terminals | BJT has three terminals viz. emitter, base and collector. | MOSFET has four terminals, i.e., source, drain, gate and body (or substrate). |
Charge carriers | In BJT, both electrons and holes act as charge carriers. | In MOSFET, either electrons or holes act as charge carriers depending on the type of channel between source and drain. |
Polarity | BJT is a bipolar device. | MOSFET is a unipolar device. |
Controlling quantity | BJT is a current controlled device. | MOSFET is a voltage controlled device. |
Input impedance | BJT has low input impedance. | MOSFET has relatively high input impedance. |
Temperature coefficient | BJT has negative temperature coefficient. | MOSFET has positive temperature coefficient. |
Switching frequency | The switching frequency BJT is low. | For MOSFET, the switching frequency is relatively high. |
Power consumption | BJT consumes more power than MOSFET. | The power consumed by a MOSFET is less than BJT |
Applications | BJT is preferred for the low current applications. It is widely used as amplifiers, oscillators and electronic switches. | MOSFET is suitable for high power applications. It is used in power supplies, etc. |
1.5 Difference Between Microcontroller and Microprocessor?
Microcontroller | Microprocessor |
---|---|
The microcontroller is the heart of an embedded system. | The microprocessor is the heart of a Computer system. |
The microcontroller has an external processor along with internal memory and i/O components | It is just a processor. Memory and I/O components have to be connected externally |
Since memory and I/0 are present internally, the circuit is small. | Since memory and I/O have to be connected externally, the circuit becomes large. |
Can be used in compact systems and hence it is an efficient technique | Cannot be used in compact systems and hence inefficient |
The cost of the entire system is low | Cost of the entire system increases |
Since external components are low, total power consumption is less and can be used with devices running on stored power like batteries. | Due to external components, the entire power consumption is high. Hence it is not suitable to used with devices running on stored power like batteries. |
Most of the microcontrollers have power-saving modes like idle mode and power-saving mode. This helps to reduce power consumption even further. | Most microprocessors do not have power-saving features. |
Since components are internal, most of the operations are internal instruction, hence speed is fast. | Since memory and I/O components are all external, each instruction will need an external operation, hence it is relatively slower. |
Microcontrollers have more number of registers, hence the programs are easier to write. | Microprocessors have less number of registers, hence more operations are memory based |
Microcontrollers are based on Harvard architecture where program memory and Data memory are separate | Microprocessors are based on the von Neumann model/architecture where programs and data are stored in the same memory module |
Used mainly in washing machines, MP3 players | Mainly used in personal computers |
1.6 What is the Difference between Oscillator and Crystal Oscillator?
An oscillator is any device or circuit that generates a periodically oscillating electric signal (usually a sine wave or a square wave). One example is the parallel LC oscillator:
A crystal is a piece of piezoelectric material that generates an oscillating sinusoidal electric signal due to the mechanical vibration of its structure. Crystals vibrate at very precise frequencies, so they produce precisely tuned outputs.
1.7 What are the different types of Buses used by Embedded Systems?
- Memory Bus: It is related to the memory-connected processor.
- Multiplexed Bus: It reads and writes in memory.
- De-multiplexed Bus: It contains 2 wires in the same bus. One has the address, and the other contains the data.
- Input/Output Bus: It multiplexes the same input and output signals by using multiplexing techniques.
1.8 What is the boot-loader?
In general, a bootloader is a code that executes at the instant the CPU comes out of reset until it passes off control of the system to the OS. It performs basic initialization of the CPU and sometimes some other peripheral devices, such as disk subsystems, sometimes network controllers, perhaps timers, DMA controller, video controller, UART(s), etc. Sometimes it can have an interactive component, or it might be completely invisible.
In Non-OS MCU you can create your own bootloader (basically an application) to check the integrity of the image and with some require initialization. You can also upgrade the image using the help of a bootloader application.
1.9 Difference between UART, SPI and I2C?
Features | UART | SPI | I2C |
---|---|---|---|
Full Form | Universal Asynchronous Receiver/Transmitter | Serial Peripheral Interface | Inter-Integrated Circuit |
Interface Diagram | |||
Pin Designations | TxD: Transmit Data RxD: Receive Data | SCLK: Serial Clock MOSI: Master Output, Slave Input MISO: Master Input, Slave Output SS: Slave Select | SDA: Serial Data SCL: Serial Clock |
Data rate | Asynchronous communication, with data rate around 230 Kbps to 460 Kbps | Maximum data rate not specified, typically supports 10 Mbps to 20 Mbps | Supports various speeds including 100 kbps, 400 kbps, and 3.4 Mbps, with some variants supporting 10 Kbps and 1 Mbps |
Distance | Lower (about 50 feet) | Higher | Higher |
Type of communication | Asynchronous | Synchronous | Synchronous |
Number of masters | Can connect only two devices at a time | One | One or more than One |
Clock | No common clock signal, independent clocks for each device | Common serial clock signal between master and slave devices | Common clock signal between multiple masters and multiple slaves |
Hardware complexity | Lesser | Less | More |
Protocol | Each company or manufacturer may have specific protocols; typically uses start and stop bits, and ACK bit for data acknowledgment | Uses slave select lines for addressing; typically uses push-pull for higher data rates | Uses open collector bus concept; addressing is simpler; supports flow control |
Software addressing | Not needed due to one-to-one connection | Uses slave select lines for addressing | Simple addressing mechanism; supports multiple slaves and masters |
Advantages
- UART:
- Simple and popular, widely available.
- Supports full duplex communication.
- SPI:
- Simple protocol with no processing overheads.
- Supports higher data rates and longer ranges.
- Requires fewer wires for communication.
- Supports more than one master.
- I2C:
- Simple addressing mechanism.
- Easy to add extra devices on the bus.
- Supports multiple slaves and masters.
Disadvantages
- UART:
- Suitable for communication between only two devices.
- SPI:
- Fixed data rate agreed upon initially.
- Hardware complexity increases with the number of slave devices.
- I2C:
- Half duplex interface.
- Requires software stack for protocol control.
1.10 List various timers in embedded systems?
- Watchdog Timer (WDT)
- General Purpose of Timer
- Interval Timer (Programmable timer)
- Systick Timer
- Real-Time Clock (RTC)
1.11 Explain what is a Watchdog Timer?
A watchdog timer (WDT) is a hardware timer that automatically generates a system reset if the main program neglects to periodically service it. It is often used to automatically reset an embedded device that hangs because of a software or hardware fault. Some systems may also refer to it as a computer operating properly (COP) timer. Many microcontrollers including the mbed processor have watchdog timer hardware.
1.12 What is the need of pull up and pull down resistor in circuit?
Pull-up resistors are resistors which are used to ensure that a wire is pulled to a high logical level in the absence of an input signal.
Pull-down resistors work in the same manner as pull-up resistors, except that they pull the pin to a logical low value.
Embedded C Programming Interview Questions
2.1 Difference between C and Embedded C?
Parameters | C | Embedded C |
---|---|---|
GENERAL | It is a structural and general purpose programming language used by the developers to build desktop-based applications. | Embedded C is generally used to develop microcontroller-based applications. |
DEPENDENCY | C language is hardware independent language. C compilers are OS dependent. | Embedded C is fully hardware dependent language. Embedded C are OS independent. |
COMPILER | For C language, the standard compilers can be used to compile and execute the program. Popular Compiler to execute a C language program are: GCC (GNU Compiler collection) Borland turbo C, Intel C++ | For Embedded C, a specific compilers that are able to generate particular hardware/micro-controller based output is used. Popular Compiler to execute a Embedded C language program are: Keil compiler BiPOM ELECTRONIC Green Hill software |
USABILITY AND APPLICATION | C language has a free-format of program coding.It is specifically used for desktop application.Optimization is normal. It is very easy to read and modify the C language.Bug fixing are very easy in a C language program. It supports other various programming languages during application.Input can be given to the program while it is running. Applications of C Program: Logical programs System software programs | Formatting depends upon the type of microprocessor that is used. It is used for limited resources like RAM and ROM.High level of optimization. It is not easy to read and modify the Embedded C language. Bug fixing is complicated in a Embedded C language program. It supports only required processor of the application, and not the programming languages. Only the pre-defined input can be given to the running program. Applications of Embedded C Program: DVD TV Camera |
2.2 Difference between compiler and interpreter?
A compiler takes the source code as a whole and translates it into object code all in one go. Once converted, the object code can be run at any time. This process is called compilation.
An interpreter translates source code into object code one instruction at a time. It is similar to a human translator translating what a person says into another language, sentence by sentence. The resulting object code is then executed immediately. The process is called interpretation.
2.3 Difference between while(1) and while(0) in C language?
Let us talk about the differences between while(1) and while(0) in C language.
Parameters | while(1) | while(0) |
Basics | The while(1) acts as an infinite loop that runs continually until a break statement is explicitly issued. | The while(0) loop means that the condition available to us will always be false. |
Function | Not just while(1), but every non-zero integer is capable of giving a similar effect like how the while(1) does.Thus, whether it is while(1), while(3), or while(-764), all of these would generate infinite loops only. | It is just the opposite of the while(1) loop. The execution of the code will, thus, never really occur. |
Uses | It is only advised to use the while(1) loop in the places where the condition always needs to be true. | It is only advised to use the while(0) loop in the places where the condition always needs to be false. |
Cons | But the usage of while(1) is not practically advisable.It is because this loop is capable of increasing the usage of the CPU and then blocking the actual code.Meaning, we can’t really come out of a while(1) loop unless someone manually closes that particular program. | It doesn’t let a line of code get executed in a program if used accidentally. There is no way out. |
2.4 Difference Between Structure and Array in C?
Parameter | Structure in C | Array in C |
Definition | It is a type of data structure in the form of a container that holds variables of different types. | It is a type of data structure that works as a container to hold variables of the very same type. Array does not support variables of multiple data types. |
Allocation of Memory | In a structure, the memory allocation for the input data doesn’t require being in consecutive memory locations. | The array stores the input data in a memory allocation of contiguous type. It means that the array stores its data in a type of memory model where the memory blocks hold consecutive addresses (it assigns memory blocks consecutively). |
Accessibility | For a user to access the elements present in a structure, they require the name of that particular element (it is mandatory for retrieval). | On the other hand, any user can easily access the elements by index in an array’s case. |
Pointer | A structure holds no concept of internal Pointer. | An array, on the other hand, implements Pointer internally. It always points at the very first element present in the array. |
Instantiation | One can create an object from the structure after a later declaration in its program. | An array does not allow the creation of an object after the declaration. |
Types of Data Type Variables | A structure includes multiple forms of data-type variables in the form of input. | A user cannot have multiple forms of data-type variables in an array because it supports only the same form of data-type variables. |
Performance | A structure becomes very slow in performance due to the presence of multiple data-types. The process of searching and accessing elements becomes very slow in these. | The process of searching and accessing elements is much faster in the case of an array due to the absence of multiple data-type variables. It is, thus, better and faster in performance. |
Syntax | struct sructure_name { element type 1; element type 2; .. }; | type name_of_array [size] |
Bit Field | You can define a Bit field in a structure. | You cannot define a Bit field in an array. |
Access | You can access the Structure elements by their names. | You can access the Array elements by their index numbers. |
Operators | The element accessing operator for a structure is a dot operator “.“ | The element accessing operator and declaration for an array is a square bracket [ ] |
Size | The various elements in a structure are of different sizes each. | The array contains various elements of the same size. |
Keyword | We use the keyword “struct” to define a structure. | No keyword is present to declare an array. |
User-defined | The structure is a user-defined form of data type. | An array isn’t user-defined. It is declared directly. |
2.5 Difference Between Structure and Union in C?
Parameter | Structure | Union |
Keyword | A user can deploy the keyword struct to define a Structure. | A user can deploy the keyword union to define a Union. |
Internal Implementation | The implementation of Structure in C occurs internally- because it contains separate memory locations allotted to every input member. | In the case of a Union, the memory allocation occurs for only one member with the largest size among all the input variables. It shares the same location among all these members/objects. |
Accessing Members | A user can access individual members at a given time. | A user can access only one member at a given time. |
Syntax | The Syntax of declaring a Structure in C is: struct [structure name] { type element_1; type element_2; .. } variable_1, …; | The Syntax of declaring a Union in C is: union [union name] { type element_1; type element_2; .. } variable_1, …; |
Size | A Structure does not have a shared location for all of its members. It makes the size of a Structure to be greater than or equal to the sum of the size of its data members. | A Union does not have a separate location for every member in it. It makes its size equal to the size of the largest member among all the data members. |
Value Altering | Altering the values of a single member does not affect the other members of a Structure. | When you alter the values of a single member, it affects the values of other members. |
Storage of Value | In the case of a Structure, there is a specific memory location for every input data member. Thus, it can store multiple values of the various members. | In the case of a Union, there is an allocation of only one shared memory for all the input data members. Thus, it stores one value at a time for all of its members. |
Initialization | In the case of a Structure, a user can initialize multiple members at the same time. | In the case of a Union, a user can only initiate the first member at a time. |
2.6 Explain What Are The Different Storage Classes In C?
Four types of storage classes are there in c.
1.Auto
2.Register
3.Static
4.Extern or Global
2.7 Explain What Are The Different Qualifiers In C?
- Volatile: A variable should be declared volatile whenever its value could change unexpectedly. In practice, only three types of variables could change:
- Memory-mapped peripheral registers
- Global variables modified by an interrupt service routine
- Global variables within a multi-threaded application
- Constant:
- The addition of a ‘const‘ qualifier indicates that the (relevant part of the) program may not modify the variable.
2.8 What Is Pass By Value And Pass By Reference?
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 that 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 are 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 are required to return more than 1 value.
2.9 Which statement is faster ++I or i+1?
- ++i instruction uses single machine instruction like INR (Increment Register) to perform the increment.
- For the instruction i+1, it requires to load the value of the variable i and then perform the INR operation on it. Due to the additional load, ++i is faster than the i+1 instruction.
Embedded C Interview Questions for Experienced Engineers
3.1 What do you understand by startup code?
A startup file is a piece of code written in assembly or C language that executes before the main() function of our embedded application. It performs various initialization steps by setting up the hardware of the microcontroller so that the user application can run. Therefore, a startup file always runs before the main() code of our embedded application.
3.2 Functions of Startup file?
Following are the main functions of a startup file:
- Disable all interrupts
- Copying initialized global, global static, and local static variable data from flash to .data section RAM memory of a microcontroller
- Copying uninitialized global, global static, and local static variable data from flash to .bss section of RAM memory and initialize .bss section of RAM to zero.
- Allocate space for the stack and initialize the stack pointer
- It also contains an array of function pointers ( interrupt vector table) that point to various interrupt vector routines such as interrupts and exceptions. The startup file also contains definitions of these interrupt or exception routines such as reset handler, NMI handler, bus fault handler, etc.
- Enable interrupts
- Calls the main function
3.3 What are the differences between process and thread?
Threads differ from traditional multitasking operating-system processes in several ways:
- The processes are typically independent, while threads exist as subsets of a process.
- The processes carry considerably more state information than threads, whereas multiple threads within a process share process state as well as memory and other resources.
- The processes have separate address spaces, whereas threads share their address space.
- The processes interact only through system-provided inter-process communication mechanisms.
- Context switching between threads in the same process typically occurs faster than context switching between processes.
3.4 What is ISR?
For every interrupt, there must be an interrupt service routine (ISR), or interrupt handler. When an interrupt occurs, the microcontroller runs the interrupt service routine. For every interrupt, there is a fixed location in memory that holds the address of its interrupt service routine, ISR. The table of memory locations set aside to hold the addresses of ISRs is called as the Interrupt Vector Table.
3.5 Role of Interrupt Vector Table in Interrupt Processing?
- ARM Cortex-M CPU has two modes of operation such as thread mode and exception. In normal execution, CPU runs in thread mode. But when an interrupt occurs the CPU transfers from thread mode to exception mode. In exception mode, nested interrupt vector controller manages all interrupt and exception requests.
- When an interrupt x occurs, the interrupt request will be sent to NVIC. If NVIC accepts the exception/interrupt request x, the next step of NVIC to find the starting address of the interrupt service routine or exception handler. The starting address of the respective ISR or exception handler is stored inside the interrupt vector table. Then NVIC uses exception number x to calculate the address of the exception by looking up the interrupt vector table and use the content of that memory address (which is an address of the respective exception handler) to execute the exception handler.
- Program counter will be loaded with the address of the exception handler and the CPU starts to execute the exception routine.
- The interrupt processing procedure of ARM cortex-M is quite lengthy. Therefore, we will post a separate article on it.
3.6 Explain What Is Interrupt Latency? How Can We Reduce It?
Interrupt latency is the time required to return from the interrupt service routine after tackling a particular interrupt. We can reduce it by writing smaller ISR routines.
3.7 What are the uses of the Keyword Static?
In the C programming language, static is used with global variables and functions to set their scope to the containing file. In local variables, static is used to store the variable in the statically allocated memory instead of the automatically allocated memory.
Note: In C, the static variables are placed in the BSS or DATA segments. The BSS segment contains the uninitialized data. The DATA segment keeps the initialized data.
3.8 What does “const int x;” mean?
It means the variable is a read-only constant integer.
3.9 Where are constant variables stored in memory?
Depends on your compiler, your system capabilities, your configuration while compiling.
gcc
puts read-only constants on the .text
section, unless instructed otherwise.
3.10 How can you protect a character pointer by some accidental modification with the pointer address?
Constant character pointer (const char*) prevents the unnecessary modifications with the pointer address in the string.
3.11 Can a variable be volatile and const both?
Yes, there are cases where it can make sense. In summary, a const volatile
means that the code cannot change the value of the variable, but something outside of the program can. Some use cases for this include:
- Read-only hardware registers
- Read-only shared memory buffers where one CPU writes and another only reads
3.12 What is a Null pointer?
A Null pointer does not point to any valid memory location. It ensures that no pointer should be used to modify as it is invalid. It is addressed as NULL.
3.13 What is the size of a pointer?
The size of a pointer in C/C++ is not fixed. It depends upon different issues like Operating system, CPU architecture etc. Usually it depends upon the word size of underlying processor for example for a 32 bit computer the pointer size can be 4 bytes for a 64 bit computer the pointer size can be 8 bytes.
3.14 When does a segmentation fault occur?
A segmentation fault or access violation occurs when a program attempts to access a memory location that is not exist, or attempts to access a memory location in a way that is not allowed.
Seg faults are mostly caused by pointers that are:
- Used to being properly initialized.
- Used after the memory they point to has been reallocated or freed.
- Used in an indexed array where the index is outside of the array bounds.
3.15 What Is Difference Between Using A Macro And Inline Function?
An inline function is a normal function that is defined by the inline keyword. An inline function is a short function that is expanded by the compiler. And its arguments are evaluated only once. An inline functions are the short length functions that are automatically made the inline functions without using the inline keyword inside the class.
Syntax of an Inline function:
inline return_type function_name ( parameters )
{
// inline function code
}
It is also called preprocessors directive. The macros are defined by the #define keyword. Before the program compilation, the preprocessor examines the program whenever the preprocessor detects the macros then preprocessor replaces the macro by the macro definition.
Syntax of Macro:
#define MACRO_NAME Macro_definition
3.16 How can you use a variable in a source file defined in another source file?
If global variables are defined in another file, you can expose them using extern
.
For example, if in file2.cpp you have variables declared as follows:
int var1;
int var2;
Then in main.cpp you can use the variable using extern
:
// define these near the top of your cpp file and then use them wherever you need to
extern int var1;
extern int var2;
3.17 Little and Big Endian Mystery?
Little and big endian are two ways of storing multibyte data-types ( int, float, etc). In little endian machines, last byte of binary representation of the multibyte data-type is stored first. On the other hand, in big endian machines, first byte of binary representation of the multibyte data-type is stored first.
Suppose integer is stored as 4 bytes (For those who are using DOS-based compilers such as C++ 3.0, integer is 2 bytes) then a variable x with value 0x01234567 will be stored as following.
3.18 List the 4 levels of testing in Embedded Systems.
The 4 levels of testing are
- Unit testing
- Integration testing
- System testing
- User acceptance testing
3.19 What is multithreading and multiprocessing?
Both Multiprocessing and Multithreading are used to increase the computing power of a system.
Multithreading:
Multithreading is a system in which multiple threads are created of a process for increasing the computing speed of the system. In multithreading, many threads of a process are executed simultaneously and process creation in multithreading is done according to economical.
Multiprocessing:
Multiprocessing is a system that has more than one or two processors. In Multiprocessing, CPUs are added for increasing computing speed of the system. Because of Multiprocessing, There are many processes are executed simultaneously.
3.20 What is Mutex?
Mutex is a mutual exclusion object that synchronizes access to a resource. It is created with a unique name at the start of a program. The mutex locking mechanism ensures only one thread can acquire the mutex and enter the critical section. This thread only releases the mutex when it exits in the critical section.
It is a special type of binary semaphore used for controlling access to the shared resource. It includes a priority inheritance mechanism to avoid extended priority inversion problems. It allows current higher priority tasks to be kept in the blocked state for the shortest time possible. However, priority inheritance does not correct priority inversion but only minimizes its effect.
Example
This is shown with the help of the following example:
wait (mutex);
.....
Critical Section
.....
signal (mutex);
3.21 What is Semaphore?
A semaphore is a signaling mechanism and a thread that is waiting on a semaphore can be signaled by another thread. This is different than a mutex as the mutex can be signaled only by the thread that called the wait function.
A semaphore uses two atomic operations, wait and signal for process synchronization.
The wait operation decrements the value of its argument S, if it is positive. If S is negative or zero, then no operation is performed.
wait(S)
{
while (S<=0);
S--;
}
The signal operation increments the value of its argument S.
signal(S)
{
S++;
}
3.22 What are the 2 types of Semaphore?
There are two types of semaphores:
- Binary Semaphores: In Binary semaphores, the value of the semaphore variable will be 0 or 1. Initially, the value of semaphore variable is set to 1 and if some process wants to use some resource then the wait() function is called and the value of the semaphore is changed to 0 from 1. The process then uses the resource and when it releases the resource then the signal() function is called and the value of the semaphore variable is increased to 1. If at a particular instant of time, the value of the semaphore variable is 0 and some other process wants to use the same resource then it has to wait for the release of the resource by the previous process. In this way, process synchronization can be achieved.
- Counting Semaphores: In Counting semaphores, firstly, the semaphore variable is initialized with the number of resources available. After that, whenever a process needs some resource, then the wait() function is called and the value of the semaphore variable is decreased by one. The process then uses the resource and after using the resource, the signal() function is called and the value of the semaphore variable is increased by one. So, when the value of the semaphore variable goes to 0 i.e all the resources are taken by the process and there is no resource left to be used, then if some other process wants to use resources then that process has to wait for its turn. In this way, we achieve the process synchronization.
3.23 Is there any difference between Deadlock and Starvation?
- Deadlock occurs when each process holds a resource and wait for other resource held by any other process.
- Starvation is the problem that occurs when high priority processes keep executing and low priority processes get blocked for indefinite time.
3.24 Difference between RS232 and RS485 (RS232 vs RS485)?
RS-232
RS-232 is the simplest of the two interfaces. It is used to connect two devices as illustrated below:
That is, the transmitter of Device 1 is connected to the receiver of Device 2 and vice versa. Both lines are single-ended with a ground reference. The standard specifies a voltage between -3 and -25 V as a logic 1 and a voltage between +3 and +25 V as a logic 0. The cable used to connect Device 1 and Device 2 can be made up of either parallel wires or a twisted pair and should generally not exceed 15 meters.
Most serial devices use a Universal Asynchronous Receiver Transmitter (UART) integrated circuits to implement a communication protocol that transmits portions of data (typically 8 bits) along with a defined set of start-bits, stop-bits, and parity-bits at a specified data rate. The transmitted data is often ASCII characters. Data rates typically range from 4800 to 115.200 baud.
RS-485
While RS-485 and RS-232 have a lot in common regarding the data format, they differ on a very significant parameter: Where RS-232 specifies single-ended connections referenced to ground, RS-485 specifies differential signaling on two lines, called A and B. Up to 32 devices can be connected via the same RS-485 bus, though only one device can “talk” at any given time (half-duplex).
RS-232 AND RS-485 DIFFERENCES
A voltage of -200 mV is specified as a logic 1, while +200 mV is specified as a logic 0. In its nature, the differential format provides common-mode noise cancellation. The differential format along with the lower voltage levels also enable higher data rates and much longer cable lengths than RS-232. Depending on the data rates, cables can be up to 1200 meters long. According to the RS-485 standard, the cables must be twisted pairs.
3.25 What is CAN?
A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other in applications without a host computer. It is a message-based protocol, designed originally for multiplex electrical wiring within automobiles to save on copper, but can also be used in many other contexts
3.26 Why CAN?
- Simple and flexible in Configuration.
- CAN is Message-Based Protocol.
- Message prioritization feature through identifier selection.
- CAN offer Multi-master Communication.
- Error Detection and Fault Confinement feature.
- Retransmission of the corrupted message automatically when the bus is idle.
3.27 Standard CAN vs Extended CAN?
In 1991, Originally Bosch released CAN specification CAN 2.0 for passenger Vehicles which explains 11- bit identifier frame architecture but later on it divided into CAN 2.0(A) which is named as standard CAN be used in passenger cars dealing with 11-bit Identifier while other is CAN2.0(B) which is known as extended CAN be used in heavy vehicles like Buses and Trucks it deals with 29-bit Identifier. So the basic difference in both standard at message Identifier field.
CAN2.0A for Standard Frame Format for Passenger Vehicles
CAN2.0B for Extended Frame Format for Heavy Vehicles
Standard or Classical CAN Frame
The standard frame format is specified in can Specification CAN2.0(A) by Robert Bosch. See below table for frame fields, sub-fields and its role in CAN Frame.Frame Format For Standard CAN
Note : Identifier available in standard CAN is 2048(2^11) but 2032 is available due to some implementation reason.
Extended CAN Frame Format
The extended Frame of CAN is almost similar to the standard frame except for its arbitration field. See below table for frame fields, sub-fields and its role in CAN Frame.Frame Format For Extended CAN
So as you can see Arbitration field in the extended frame format only differ from the standard CAN means extended CAN architecture designed in such a way that standard and extended CAN coexist on the same network.
Note: Available Identifier in Extended CAN is about 500 million (2^29).
3.28 How do CAN bus modules communicate?
CAN bus uses two dedicated wires for communication. The wires are called CAN high and CAN low. When the CAN bus is in idle mode, both lines carry 2.5V. When data bits are being transmitted, the CAN high line goes to 3.75V and the CAN low drops to 1.25V, thereby generating a 2.5V differential between the lines. Since communication relies on a voltage differential between the two bus lines, the CAN bus is NOT sensitive to inductive spikes, electrical fields or other noise. This makes CAN bus a reliable choice for networked communications on mobile equipment.
3.29 Why Can Is Having 120 Ohms At Each End?
An ISO 11898 CAN bus must be terminated. This is done using a resistor of 120 Ohms in each end of the bus. The termination serves two purposes:
- Remove the signal reflections at the end of the bus.
- Ensure the bus gets correct DC levels.
Leave a comment