Top 40 Embedded C Interview Questions
Q1. Can A Variable Be Both Const And Volatile?
The const keyword make certain that the value of the variable declared as const can not be modified. This statement holds actual within the scope of the program. The value can still be changed with the aid of outside intervention. So, the usage of const with risky key-word makes best sense.
Q2. Advantages And Disadvantages Of Using Macro And Inline Functions?
The gain of the macro and inline characteristic is that the overhead for argument passing and stuff is reduced as the feature are in-lined. The advantage of macro characteristic is that we are able to write type insensitive capabilities. It is likewise the downside of macro function as macro capabilities can not do validation check. The macro and inline characteristic also will increase the dimensions of the executable.
Q3. What Is Null Pointer And What Is Its Use?
The NULL is a macro described in C. Null pointer really me a pointer that does not factor to any valid place. We outline a pointer to be null while we want to ensure that the pointer does now not point to any legitimate area and no longer to use that pointer to alternate something. If we don't use null pointer, then we can not affirm whether or not this pointer factors to any legitimate vicinity or now not.
Q4. Can Structures Be Passed To The Functions By Value?
Passing shape by its cost to a function is feasible, but now not an excellent programming practice. First of all, if we bypass the shape with the aid of cost and the function modifications some of the ones values, then the fee trade isn't reflected in caller function. Also, if the shape is large, then passing the structure by means of value me copying the whole shape to the function argument stack that can sluggish this system with the aid of a enormous amount.
Q5. Why Cannot Arrays Be Passed By Values To Functions?
In C, the array call itself represents the deal with of the first element. So, despite the fact that we pass the array call as argument, it is going to be surpassed as reference and no longer its deal with.
Q6. Can We Use Printf Inside Isr?
Printf function in ISR is not supported due to the fact printf characteristic is not reentrant, thread secure and makes use of dynamic reminiscence allocation which takes plenty of time and can have an effect on the speed of an ISR up to a awesome volume.
Q7. What Is Job Of Preprocessor, Compiler, Assembler And Linker ?
The preprocessor commands are processed and expanded by way of the preprocessor before actual compilation. After preprocessing, the compiler takes the output of the preprocessor and the supply code, and generates assembly code. Once compiler completes its paintings, the assembler takes the assembly code and produces an assembly list with offsets and generate object documents.
The linker combines object files or libraries and produces a unmarried executable file. It additionally resolves references to external symbols, assigns final addresses to functions and variables, and revises code and statistics to mirror new addresses.
Q8. Why ++n Executes Faster Than N+1?
The expression ++n requires a unmarried machine preparation consisting of INR to carry out the increment operation. In case of n+1, other than INR, other commands are required to load the fee of n. That is why ++n is quicker.
Q9. Can We Use Any Function Inside Isr?
We can use function inside ISR so long as that feature is not invoked from different part of the code.
Q10. What Is Void Pointer And What Is Its Use?
The void pointer me that it points to a variable that may be of any kind. Other suggestions points to a selected sort of variable whilst void pointer is a truly widespread pointer and may be pointed to any records kind, be it standard information kind(int, char and many others) or person define records type (structure, union etc.). We can skip any form of pointer and reference it as a void pointer. But to dereference it, we need to kind the void pointer to correct facts type.
Q11. Is Count Down To Zero Loop Better Than Count_up_loops?
Countdown to 0 loops are higher. Reason at the back of that is that at loop termination, comparison to zero may be optimized via the compiler. Most processors have education for comparing to zero. So they don't need to load the loop variable and the maximum cost, subtract them after which evaluate to zero. That is why matter all the way down to 0 loop is better.
Q12. How To Reduce Interrupt Latency?
Interrupt latency may be minimized by means of writing short ISR habitual and by now not delaying interrupts for more time.
Q13. Can Static Variables Be Declared In A Header File?
A static variable can't be declared with out defining it. A static variable can be described in the header report. But doing so, the result will be having a private reproduction of that variable in every supply document which incorporates the header file. So it will likely be wise not to declare a static variable in header report, except you're handling a exclusive scenario.
Q14. What Is The Difference Between Hard Real-time And Soft Real-time Os?
A Hard actual-time gadget strictly adheres to the cut-off date related to the mission. If the device fails to fulfill the cut-off date, even as soon as, the system is taken into consideration to have failed. In case of a gentle actual-time device, missing a deadline is appropriate. In this kind of system, a important real-time project gets priority over other duties and keeps that precedence until it completes.
Q15. What Is Kernel Paging?
Paging is a reminiscence management scheme by which computers can keep and retrieve statistics from the secondary reminiscence storage while wanted in to number one memory. In this scheme, the running device retrieves information from secondary storage in same-length blocks called pages. The paging scheme allows the physical address area of a method to be non continuous. Paging lets in OS to use secondary storage for statistics that does not fit entirely into physical memory.
Q16. What Is Top Half & Bottom Half Of A Kernel?
Sometimes to handle an interrupt, a sizeable amount of labor has to be carried out. But it conflicts with the velocity need for an interrupt handler. To manage this case, Linux splits the handler into components – Top 1/2 and Bottom 1/2. The pinnacle half is the routine that without a doubt responds to the interrupt. The backside half of alternatively is a recurring that is scheduled by way of the upper half of to be executed later at a more secure time.
All interrupts are enabled during execution of the bottom half. The top half of saves the device records into the unique buffer, schedules bottom 1/2 and exits. The bottom half of does the relaxation. This manner the pinnacle half of can carrier a new interrupt whilst the bottom half of is working at the previous.
Q17. Can We Put Breakpoint Inside Isr?
Putting a breakpoint internal ISR is not an amazing concept because debugging will make the effort and a difference of half of or greater 2d will result in different behavior of hardware. To debug ISR, definitive logs are better.
Q18. What Is Dangling Pointer?
If a pointer is de-allotted and freed and the pointer is not assigned to NULL, then it could nonetheless incorporate that cope with and having access to the pointer me that we're looking to get right of entry to that place and it will supply an errors. This form of pointer is called dangling pointer.
Q19. What Is Size Of Character, Integer, Integer Pointer, Character Pointer?
The sizeof person is 1 byte.
Size of integer is four bytes.
Size of integer pointer and man or woman is 8 bytes on 64 bit system and four bytes on 32 bit device.
Q20. What Is Interrupt Latency?
Interrupt latency is the time required for an ISR responds to an interrupt.
Q21. Can A Pointer Be Volatile?
If we see the declaration volatile int *p, it me that the pointer itself is not unstable and points to an integer that is unstable. This is to inform the compiler that pointer p is pointing to an integer and the cost of that integer may exchange abruptly although there's no code indicating so within the program.
Q22. What Is Isr?
An ISR(Interrupt Service Routine) is an interrupt handler, a callback subroutine which is known as while a interrupt is encountered.
Q23. What Is The Difference Between Static Linking And Dynamic Linking ?
In static linking, all the library modules used inside the software are located in the final executable report making it large in size. This is executed by means of the linker. If the modules used inside the application are changed after linking, then re-compilation is needed. The gain of static linking is that the modules are present in an executable document. We do not want to worry about compatibility troubles.
In case of dynamic linking, best the names of the module used are gift in the executable file and the real linking is finished at run time when the program and the library modules both are gift within the reminiscence. That is why, the executables are smaller in length. Modification of the library modules used does not force re-compilation. But dynamic linking may also face compatibility troubles with the library modules used.
Q24. What Are Inline Functions?
The ARM compilers help inline capabilities with the key-word __inline. These capabilities have a small definition and the function frame is substituted in every call to the inline feature. The argument passing and stack upkeep is skipped and it effects in quicker code execution, but it increases code size, specifically if the inline feature is massive or one inline feature is used often.
Q25. What Are The Uses Of The Keyword Volatile?
Volatile keyword is used to prevent compiler to optimize a variable that could exchange all at once past compiler's comprehension. Suppose, we've a variable which can be changed from scope out of the program, say via a signal, we do not want the compiler to optimize it. Rather than optimizing that variable, we want the compiler to load the variable whenever it's miles encountered. If we declare a variable risky, compiler will no longer cache it in its sign in.
Q26. What Type Of Scheduling Is There In Rtos?
RTOS makes use of preemptive scheduling. In preemptive scheduling, the higher precedence project can interrupt a walking technique and the interrupted manner could be resumed later.
Q27. Difference Between Risc And Cisc Processor?
RISC (Reduced Instruction Set Computer) should perform a few units of simple instructions concurrently. Fewer tristors are used to manufacture RISC, which makes RISC cheaper. RISC has uniform instruction set and people instructions are also fewer in variety. Due to the less variety of commands as well as commands being simple, the RISC computers are quicker. RISC emphasise on software in preference to hardware. RISC can execute commands in a single machine cycle.
CISC (Complex Instruction Set Computer) is able to executing more than one operations through a unmarried education. CISC have rich and complex education set and extra range of addressing modes. CISC emphasise on hardware alternatively that software, making it dearer than RISC. It has a small code length, high cycles per 2nd and it's far slower compared to RISC.
Q28. What Is Priority Inheritance?
Priority inheritance is a technique to the concern inversion hassle. The technique watching for any aid which has a resource lock may have the most priority. This is priority inheritance. When one or extra excessive priority jobs are blocked via a task, the authentic precedence task is left out and execution of important phase might be assigned to the activity with the highest precedence on this expanded situation. The job returns to the original priority stage quickly after executing the vital section.
Q29. What Is Virtual Memory?
Virtual memory is a technique that lets in methods to allocate reminiscence in case of physical reminiscence shortage the usage of automated garage allocation upon a request. The benefit of the virtual reminiscence is that the program may have a larger reminiscence than the physical reminiscence. It lets in big digital reminiscence to be furnished when handiest a smaller physical reminiscence is available. Virtual reminiscence can be applied the use of paging.
A paging system is pretty just like a paging device with swapping. When we want to execute a procedure, we swap it into memory. Here we use a lazy swapper referred to as pager instead of swapping the entire procedure into memory. When a manner is to be swapped in, the pager guesses which pages can be used primarily based on some set of rules, before the process is swapped out again. Instead of swapping entire method, the pager brings handiest the vital pages into reminiscence. By that manner, it avoids reading in useless reminiscence pages, lowering the switch time and the quantity of bodily reminiscence.
Q30. What Is The Use Of Volatile Keyword?
The C's risky keyword is a qualifier that tells the compiler now not to optimize when carried out to a variable. By maintaining a variable unstable, we are able to inform the compiler that the fee of the variable may also exchange any second from outside of the scope of the program. A variable must be declared risky each time its price should trade all at once and beyond the comprehension of the compiler.
In those cases it is required now not to optimize the code, doing so may additionally result in misguided result and load the variable each time it is used within the program. Volatile keyword is beneficial for memory-mapped peripheral registers, worldwide variables changed via an interrupt provider habitual, global variables accessed by using a couple of responsibilities within a multi-threaded software.
Q31. What Happens When Recursive Functions Are Declared Inline?
Inlining an recursive function reduces the overhead of saving context on stack. But, inline is merely an offer to the compiler and it does now not guarantee that a feature will be inlined. Obviously, the compiler might not be capable of inline a recursive feature infinitely. It won't inline it in any respect or it could inline it, only a few ranges deep.
Q32. What Is Wild Pointer?
A pointer that is not initialized to any valid cope with or NULL is taken into consideration as wild pointer. Consider the following code fragment -
int *p;
*p = 20;
Here p is not initialized to any valid deal with and nevertheless we are trying to get entry to the cope with. The p gets any garbage place and the next statement will corrupt that reminiscence region.
Q33. What Is The Concatenation Operator?
The Concatenation operator (##) in macro is used to concatenate two arguments. Literally, we are able to say that the arguments are concatenated, but honestly their cost aren't concatenated. Think it this way, if we pass A and B to a macro which makes use of ## to concatenate those two, then the end result will be AB.
Consider the example to clean the confusion-
#define SOME_MACRO(a, b) a##b
most important()
int var = 15;
printf(“%d”, SOME_MACRO(v, ar));
Output of the above program might be 15.
Q34. What Are The Uses Of The Keyword Static?
Static keyword can be used with variables as well as features. A variable declared static can be of static garage magnificence and within a feature, it continues its value between calls to that function. A variable declared as static within a document, scope of that variable might be within that report, but it cannot be accessed by means of other documents.
Functions declared static inside a module may be accessed by using different features inside that module. That is, the scope of the characteristic is localized to the module inside which it's miles declared.
Q35. Can Include Files Be Nested?
Yes. Include documents can be nested any range of times. But you have to ensure that you aren't which includes the identical file two times. There is no restriction to how many header documents that can be included. But the variety may be compiler structured, on the grounds that along with more than one header documents may additionally motive your pc to run out of stack memory.
Q36. What Is Priority Inversion?
If duties percentage a resource, the only with higher precedence will run first. However, if the lower-precedence assignment is the use of the shared aid whilst the higher-priority project will become equipped, then the better-precedence undertaking need to watch for the lower-precedence mission to complete. In this state of affairs, even though the assignment has higher priority it wishes to wait for the crowning glory of the decrease-precedence challenge with the shared aid. This is called priority inversion.
Q37. What Is Rtos?
In an running machine, there is a module referred to as the scheduler, which schedules distinct tasks and determines when a technique will execute on the processor. This way, the multi-tasking is accomplished. The scheduler in a Real Time Operating System (RTOS) is designed to offer a predictable execution pattern. In an embedded gadget, a certain occasion should be entertained in strictly described time.
To meet actual time requirements, the behaviour of the scheduler have to be predictable. This kind of OS which have a scheduler with predictable execution sample is called Real Time OS(RTOS).
The capabilities of an RTOS are:
Context switching latency have to be brief.
Interrupt latency have to be brief.
Interrupt dispatch latency should be brief.
Reliable and time certain inter manner mechanisms.
Should assist kernel preemption.
Q38. Which Parameters Decide The Size Of Data Type For A Processor ?
Actually, compiler is the one liable for length of the records type. But it's miles proper so long as OS allows that. If it is not allowable via OS, OS can force the size.
Q39. What Is Return Type Of Isr?
ISR does not return some thing. An ISR returns nothing due to the fact there's no caller within the code to study the back values.
Q40. Significance Of Watchdog Timer In Embedded Systems?
The watchdog timer is a timing tool with a predefined time c program languageperiod. During that interval, some occasion may also arise in any other case the device generates a day trip sign. It is used to reset to the unique kingdom every time some irrelevant events take region that could result in system malfunction. It is commonly operated by using counter devices.

