Embedded C Interview Questions & Answers

4 avg. rating (80% score) - 1 votes

Embedded C Interview Questions & Answers

Searching for a new job know a day has become very difficult for everyone. Don’t know when companies will keep interviews properly. So, in such circumstances it is very difficult for participants. To clear all such confusion and doubts regarding interview job positions and interview question and answers Wisdomjobs have clearly stated everything on the site page. If you are familiar with the Embedded Concepts then there are many leading companies that offer job roles like Embedded Developer - C/C++, Embedded Developer - Software Development & Architecture - C/C++, Embedded C Programmer, Embedded Firmware Developer - C/c++, Bluetooth Developer/Manager - Embedded C, Senior Engineer/Tech Lead - C/C++ and many other roles too. For more details Regarding Embedded C jobs and Embedded C Interview Question and Answers visit our site www.wisdomjobs.com.

Embedded C Interview Questions

Embedded C Interview Questions
    1. Question 1. What Is The Use Of Volatile Keyword?

      Answer :

      The C's volatile keyword is a qualifier that tells the compiler not to optimize when applied to a variable. By declaring a variable volatile, we can tell the compiler that the value of the variable may change any moment from outside of the scope of the program. A variable should be declared volatile whenever its value could change unexpectedly and beyond the comprehension of the compiler.

      In those cases it is required not to optimize the code, doing so may lead to erroneous result and load the variable every time it is used in the program. Volatile keyword is useful for memory-mapped peripheral registers, global variables modified by an interrupt service routine, global variables accessed by multiple tasks within a multi-threaded application.

    2. Question 2. Can A Variable Be Both Const And Volatile?

      Answer :

      The const keyword make sure that the value of the variable declared as const can't be changed. This statement holds true in the scope of the program. The value can still be changed by outside intervention. So, the use of const with volatile keyword makes perfect sense.

    3. Question 3. Can A Pointer Be Volatile?

      Answer :

      If we see the declaration volatile int *p, it means that the pointer itself is not volatile and points to an integer that is volatile. This is to inform the compiler that pointer p is pointing to an integer and the value of that integer may change unexpectedly even if there is no code indicating so in the program.

    4. Question 4. What Is Size Of Character, Integer, Integer Pointer, Character Pointer?

      Answer :

      The sizeof character is 1 byte.

      Size of integer is 4 bytes.

      Size of integer pointer and character is 8 bytes on 64 bit machine and 4 bytes on 32 bit machine.

    5. Question 5. What Is Null Pointer And What Is Its Use?

      Answer :

      The NULL is a macro defined in C. Null pointer actually means a pointer that does not point to any valid location. We define a pointer to be null when we want to make sure that the pointer does not point to any valid location and not to use that pointer to change anything. If we don't use null pointer, then we can't verify whether this pointer points to any valid location or not.

    6. Question 6. What Is Void Pointer And What Is Its Use?

      Answer :

      The void pointer means that it points to a variable that can be of any type. Other pointers points to a specific type of variable while void pointer is a somewhat generic pointer and can be pointed to any data type, be it standard data type(int, char etc) or user define data type (structure, union etc.). We can pass any kind of pointer and reference it as a void pointer. But to dereference it, we have to type the void pointer to correct data type.

    7. Question 7. What Is Isr?

      Answer :

      An ISR(Interrupt Service Routine) is an interrupt handler, a callback subroutine which is called when a interrupt is encountered.

    8. Question 8. What Is Return Type Of Isr?

      Answer :

      ISR does not return anything. An ISR returns nothing because there is no caller in the code to read the returned values.

    9. Question 9. What Is Interrupt Latency?

      Answer :

      Interrupt latency is the time required for an ISR responds to an interrupt.

    10. Question 10. How To Reduce Interrupt Latency?

      Answer :

      Interrupt latency can be minimized by writing short ISR routine and by not delaying interrupts for more time.

    11. Question 11. Can We Use Any Function Inside Isr?

      Answer :

      We can use function inside ISR as long as that function is not invoked from other portion of the code.

    12. Question 12. Can We Use Printf Inside Isr?

      Answer :

      Printf function in ISR is not supported because printf function is not reentrant, thread safe and uses dynamic memory allocation which takes a lot of time and can affect the speed of an ISR up to a great extent.

    13. Question 13. Can We Put Breakpoint Inside Isr?

      Answer :

      Putting a breakpoint inside ISR is not a good idea because debugging will take some time and a difference of half or more second will lead to different behavior of hardware. To debug ISR, definitive logs are better.

    14. Question 14. Can Static Variables Be Declared In A Header File?

      Answer :

      A static variable cannot be declared without defining it. A static variable can be defined in the header file. But doing so, the result will be having a private copy of that variable in each source file which includes the header file. So it will be wise not to declare a static variable in header file, unless you are dealing with a different scenario.

    15. Question 15. Is Count Down To Zero Loop Better Than Count_up_loops?

      Answer :

      Countdown to zero loops are better. Reason behind this is that at loop termination, comparison to zero can be optimized by the compiler. Most processors have instruction for comparing to zero. So they don't need to load the loop variable and the maximum value, subtract them and then compare to zero. That is why count down to zero loop is better.

    16. Question 16. What Are Inline Functions?

      Answer :

      The ARM compilers support inline functions with the keyword __inline. These functions have a small definition and the function body is substituted in each call to the inline function. The argument passing and stack maintenance is skipped and it results in faster code execution, but it increases code size, particularly if the inline function is large or one inline function is used often.

    17. Question 17. Can Include Files Be Nested?

      Answer :

      Yes. Include files can be nested any number of times. But you have to make sure that you are not including the same file twice. There is no limit to how many header files that can be included. But the number can be compiler dependent, since including multiple header files may cause your computer to run out of stack memory.

    18. Question 18. What Are The Uses Of The Keyword Static?

      Answer :

      Static keyword can be used with variables as well as functions. A variable declared static will be of static storage class and within a function, it maintains its value between calls to that function. A variable declared as static within a file, scope of that variable will be within that file, but it can't be accessed by other files.

      Functions declared static within a module can be accessed by other functions within that module. That is, the scope of the function is localized to the module within which it is declared.

    19. Question 19. What Are The Uses Of The Keyword Volatile?

      Answer :

      Volatile keyword is used to prevent compiler to optimize a variable which can change unexpectedly beyond compiler's comprehension. Suppose, we have a variable which may be changed from scope out of the program, say by a signal, we do not want the compiler to optimize it. Rather than optimizing that variable, we want the compiler to load the variable every time it is encountered. If we declare a variable volatile, compiler will not cache it in its register.

    20. Question 20. What Is Top Half & Bottom Half Of A Kernel?

      Answer :

      Sometimes to handle an interrupt, a substantial amount of work has to be done. But it conflicts with the speed need for an interrupt handler. To handle this situation, Linux splits the handler into two parts – Top half and Bottom half. The top half is the routine that actually responds to the interrupt. The bottom half on the other hand is a routine that is scheduled by the upper half to be executed later at a safer time.

      All interrupts are enabled during execution of the bottom half. The top half saves the device data into the specific buffer, schedules bottom half and exits. The bottom half does the rest. This way the top half can service a new interrupt while the bottom half is working on the previous.

    21. Question 21. Difference Between Risc And Cisc Processor?

      Answer :

      RISC (Reduced Instruction Set Computer) could carry out a few sets of simple instructions simultaneously. Fewer transistors are used to manufacture RISC, which makes RISC cheaper. RISC has uniform instruction set and those instructions are also fewer in number. Due to the less number of instructions as well as instructions being simple, the RISC computers are faster. RISC emphasise on software rather than hardware. RISC can execute instructions in one machine cycle.

      CISC (Complex Instruction Set Computer) is capable of executing multiple operations through a single instruction. CISC have rich and complex instruction set and more number of addressing modes. CISC emphasise on hardware rather that software, making it costlier than RISC. It has a small code size, high cycles per second and it is slower compared to RISC.

    22. Question 22. What Is Rtos?

      Answer :

      In an operating system, there is a module called the scheduler, which schedules different tasks and determines when a process will execute on the processor. This way, the multi-tasking is achieved. The scheduler in a Real Time Operating System (RTOS) is designed to provide a predictable execution pattern. In an embedded system, a certain event must be entertained in strictly defined time.

      To meet real time requirements, the behaviour of the scheduler must be predictable. This type of OS which have a scheduler with predictable execution pattern is called Real Time OS(RTOS).

      The features of an RTOS are:

      • Context switching latency should be short.
      • Interrupt latency should be short.
      • Interrupt dispatch latency should be short.
      • Reliable and time bound inter process mechanisms.
      • Should support kernel preemption.

    23. Question 23. What Is The Difference Between Hard Real-time And Soft Real-time Os?

      Answer :

      A Hard real-time system strictly adheres to the deadline associated with the task. If the system fails to meet the deadline, even once, the system is considered to have failed. In case of a soft real-time system, missing a deadline is acceptable. In this type of system, a critical real-time task gets priority over other tasks and retains that priority until it completes.

    24. Question 24. What Type Of Scheduling Is There In Rtos?

      Answer :

      RTOS uses preemptive scheduling. In preemptive scheduling, the higher priority task can interrupt a running process and the interrupted process will be resumed later.

    25. Question 25. What Is Priority Inversion?

      Answer :

      If two tasks share a resource, the one with higher priority will run first. However, if the lower-priority task is using the shared resource when the higher-priority task becomes ready, then the higher-priority task must wait for the lower-priority task to finish. In this scenario, even though the task has higher priority it needs to wait for the completion of the lower-priority task with the shared resource. This is called priority inversion.

    26. Question 26. What Is Priority Inheritance?

      Answer :

      Priority inheritance is a solution to the priority inversion problem. The process waiting for any resource which has a resource lock will have the maximum priority. This is priority inheritance. When one or more high priority jobs are blocked by a job, the original priority assignment is ignored and execution of critical section will be assigned to the job with the highest priority in this elevated scenario. The job returns to the original priority level soon after executing the critical section.

    27. Question 27. What Is Virtual Memory?

      Answer :

      Virtual memory is a technique that allows processes to allocate memory in case of physical memory shortage using automatic storage allocation upon a request. The advantage of the virtual memory is that the program can have a larger memory than the physical memory. It allows large virtual memory to be provided when only a smaller physical memory is available. Virtual memory can be implemented using paging.

      A paging system is quite similar to a paging system with swapping. When we want to execute a process, we swap it into memory. Here we use a lazy swapper called pager rather than swapping the entire process into memory. When a process is to be swapped in, the pager guesses which pages will be used based on some algorithm, before the process is swapped out again. Instead of swapping whole process, the pager brings only the necessary pages into memory. By that way, it avoids reading in unnecessary memory pages, decreasing the swap time and the amount of physical memory.

    28. Question 28. What Is Kernel Paging?

      Answer :

      Paging is a memory management scheme by which computers can store and retrieve data from the secondary memory storage when needed in to primary memory. In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. The paging scheme allows the physical address space of a process to be non continuous. Paging allows OS to use secondary storage for data that does not fit entirely into physical memory.

    29. Question 29. Can Structures Be Passed To The Functions By Value?

      Answer :

      Passing structure by its value to a function is possible, but not a good programming practice. First of all, if we pass the structure by value and the function changes some of those values, then the value change is not reflected in caller function. Also, if the structure is big, then passing the structure by value means copying the whole structure to the function argument stack which can slow the program by a significant amount.

    30. Question 30. Why Cannot Arrays Be Passed By Values To Functions?

      Answer :

      In C, the array name itself represents the address of the first element. So, even if we pass the array name as argument, it will be passed as reference and not its address.

    31. Question 31. Advantages And Disadvantages Of Using Macro And Inline Functions?

      Answer :

      The advantage of the macro and inline function is that the overhead for argument passing and stuff is reduced as the function are in-lined. The advantage of macro function is that we can write type insensitive functions. It is also the disadvantage of macro function as macro functions can't do validation check. The macro and inline function also increases the size of the executable.

    32. Question 32. What Happens When Recursive Functions Are Declared Inline?

      Answer :

      Inlining an recursive function reduces the overhead of saving context on stack. But, inline is merely a suggestion to the compiler and it does not guarantee that a function will be inlined. Obviously, the compiler won't be able to inline a recursive function infinitely. It may not inline it at all or it may inline it, just a few levels deep.

    33. Question 33. What Is The Concatenation Operator?

      Answer :

      The Concatenation operator (##) in macro is used to concatenate two arguments. Literally, we can say that the arguments are concatenated, but actually their value are not concatenated. Think it this way, if we pass A and B to a macro which uses ## to concatenate those two, then the result will be AB.

      Consider the example to clear the confusion-

      #define SOME_MACRO(a, b) a##b



        int var = 15;

        printf(“%d”, SOME_MACRO(v, ar));


      Output of the above program will be 15.

    34. Question 34. Which Parameters Decide The Size Of Data Type For A Processor ?

      Answer :

      Actually, compiler is the one responsible for size of the data type. But it is true as long as OS allows that. If it is not allowable by OS, OS can force the size.

    35. Question 35. What Is Job Of Preprocessor, Compiler, Assembler And Linker ?

      Answer :

      The preprocessor commands are processed and expanded by the preprocessor before actual compilation. After preprocessing, the compiler takes the output of the preprocessor and the source code, and generates assembly code. Once compiler completes its work, the assembler takes the assembly code and produces an assembly listing with offsets and generate object files.

      The linker combines object files or libraries and produces a single executable file. It also resolves references to external symbols, assigns final addresses to functions and variables, and revises code and data to reflect new addresses.

    36. Question 36. What Is The Difference Between Static Linking And Dynamic Linking ?

      Answer :

      In static linking, all the library modules used in the program are placed in the final executable file making it larger in size. This is done by the linker. If the modules used in the program are modified after linking, then re-compilation is needed. The advantage of static linking is that the modules are present in an executable file. We don't want to worry about compatibility issues.

      In case of dynamic linking, only the names of the module used are present in the executable file and the actual linking is done at run time when the program and the library modules both are present in the memory. That is why, the executables are smaller in size. Modification of the library modules used does not force re-compilation. But dynamic linking may face compatibility issues with the library modules used.

    37. Question 37. Significance Of Watchdog Timer In Embedded Systems?

      Answer :

      The watchdog timer is a timing device with a predefined time interval. During that interval, some event may occur or else the device generates a time out signal. It is used to reset to the original state whenever some inappropriate events take place which can result in system malfunction. It is usually operated by counter devices.

    38. Question 38. Why ++n Executes Faster Than N+1?

      Answer :

      The expression ++n requires a single machine instruction such as INR to carry out the increment operation. In case of n+1, apart from INR, other instructions are required to load the value of n. That is why ++n is faster.

    39. Question 39. What Is Wild Pointer?

      Answer :

      A pointer that is not initialized to any valid address or NULL is considered as wild pointer. Consider the following code fragment -

      int *p;

      *p = 20;

      Here p is not initialized to any valid address and still we are trying to access the address. The p will get any garbage location and the next statement will corrupt that memory location.

    40. Question 40. What Is Dangling Pointer?

      Answer :

      If a pointer is de-allocated and freed and the pointer is not assigned to NULL, then it may still contain that address and accessing the pointer means that we are trying to access that location and it will give an error. This type of pointer is called dangling pointer.

Linux Embedded Systems Tutorial

Embedded C Practice Tests

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Linux Embedded systems Tutorial