InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is a reentrant function? |
|
Answer» A function is CALLED reentrant if the function can be INTERRUPTED in the middle of the execution and be safely called again (re-entered) to complete the execution. The interruption can be in the form of external EVENTS or signals or internal signals like CALL or jump. The reentrant function RESUMES at the point where the execution was left off and proceeds to completion. |
|
| 2. |
What do you understand by the pre-decrement and post-decrement operators? |
|
Answer» The Pre-decrement OPERATOR (--operand) is used for decrementing the value of the variable by 1 before assigning the variable value. #include < stdio.h > int main(){ int x = 100, y; y = --x; //pre-decrememt OPERATORS -- first decrements the value and then it is assigned PRINTF("y = %d\n", y); // Prints 99 printf("x = %d\n", x); // Prints 99 RETURN 0; }The Post-decrement operator (operand--) is used for decrementing the value of a variable by 1 after assigning the variable value. #include < stdio.h > int main(){ int x = 100, y; y = x--; //post-decrememt operators -- first assigns the value and then it is decremented printf("y = %d\n", y); // Prints 100 printf("x = %d\n", x); // Prints 99 return 0; } |
|
| 3. |
Is it possible to declare a static variable in a header file? |
|
Answer» Variables defined with static are initialized once and persists until the end of the program and are local only to the block it is defined. A static variables declaration REQUIRES definition. It can be defined in a header file. But if we do so, a private COPY of the variable of the header file will be present in each source file the header is INCLUDED. This is not preferred and HENCE it is not recommended to use static variables in a header file. |
|
| 4. |
Is it possible for a variable to be both volatile and const? |
|
Answer» The const keyword is used when we want to ensure that the VARIABLE value should not be changed. However, the value can STILL be changed due to external INTERRUPTS or events. So, we can use const with volatile keywords and it won’t CAUSE any PROBLEM. |
|
| 5. |
What are the differences between Inline and Macro Function? |
||||||||||||||||||
Answer»
|
|||||||||||||||||||
| 6. |
What do you understand by segmentation fault? |
|
Answer» A segmentation fault occurs most COMMONLY and often leads to crashes in the PROGRAMS. It occurs when a program INSTRUCTION tries to access a memory ADDRESS that is prohibited from getting ACCESSED. |
|
| 7. |
How will you use a variable defined in source file1 inside source file2? |
|
Answer» We can achieve this by making USE of the “extern” KEYBOARD. It ALLOWS the variable to be accessible from one file to another. This can be handled more cleanly by creating a header file that just CONSISTS of extern variable declarations. This header file is then included in the source files which uses the extern variables. Consider an example where we have a header file named variables.h and a source file named sc_file.c. /* variables.h*/extern int global_variable_x;/* sc_file.c*/#include "variables.h" /* Header variables included */#include <stdio.h>VOID demoFunction(void){ printf("Value of Global Variable X: %d\n", global_variable_x++);} |
|
| 8. |
What do you understand by Interrupt Latency? |
|
Answer» Interrupt latency refers to the TIME taken by ISR to respond to the interrupt. The lesser the latency FASTER is the response to the interrupt EVENT. |
|
| 9. |
What Is Concatenation Operator in Embedded C? |
|
Answer» The Concatenation operator is indicated by the USAGE of ##. It is used in macros to perform concatenation of the arguments in the macro. We need to keep note that only the arguments are concatenated, not the VALUES of those arguments. For example, if we have the FOLLOWING piece of CODE: #define CUSTOM_MACRO(x, y) x##ymain(){ int xValue = 20; printf(“%d”, CUSTOM_MACRO(x, Value)); //Prints 20}We can think of it like this if arguments x and y are passed, then the macro just returns xy -> The concatenation of x and y. |
|
| 10. |
What are the differences between the const and volatile qualifiers in embedded C? |
||||||
Answer»
|
|||||||
| 11. |
Why do we use the volatile keyword? |
|
Answer» The volatile keyword is mainly used for preventing a compiler from optimizing a VARIABLE that might change its behaviour unexpectedly post the optimization. Consider a scenario where we have a variable where there is a possibility of its value getting updated by some EVENT or a signal, then we need to tell the compiler not to OPTIMIZE it and LOAD that variable every time it is called. To inform the compiler, we use the keyword volatile at the time of variable declaration. // Declaring volatile variable - SYNTAX// volatile datatype variable_name;volatile int X;Here, x is an integer variable that is defined as a volatile variable. |
|
| 12. |
What is Void Pointer in Embedded C and why is it used? |
|
Answer» Void pointers are those pointers that POINT to a variable of any type. It is a GENERIC pointer as it is not DEPENDENT on any of the inbuilt or user-defined data types while referencing. During dereferencing of the pointer, we require the correct data type to which the data needs to be dereferenced. For EXAMPLE: int num1 = 20; //variable of int datatype void *ptr; //Void Pointer*ptr = &num1; //Point the pointer to int dataprint("%d",(*(int*)ptr)); //Dereferencing requires specific data type char c = 'a';*ptr = &c; //Same void pointer can be used to point to data of different type -> reusabilityprint("%c",(*(char*)ptr));Void pointers are used mainly because of their nature of re-usability. It is reusable because any type of data can be STORED. |
|
| 13. |
What is ISR? |
|
Answer» ISR expands to Interrupt SERVICE Routines. These are the procedures stored at a particular memory location and are called when CERTAIN interrupts occur. Interrupt refers to the signal sent to the processor that indicates there is a high-PRIORITY event that requires immediate ATTENTION. The processor suspends the normal flow of the program, executes the instructions in ISR to cater for the high priority event. POST execution of the ISR, the normal flow of the program resumes. The following diagrams represent the flow of ISR. |
|
| 14. |
What do you understand by startup code? |
|
Answer» A startup CODE is that piece of code that is called before the execution of the MAIN FUNCTION. This is used for creating a basic platform for the application and it is written in ASSEMBLY language. |
|
| 15. |
What is Embedded C Programming? How is Embedded C different from C language? |
||||||||
|
Answer» Embedded C is a programming LANGUAGE that is an extension of C programming. It uses the same syntax as C and it is called “embedded” because it is USED widely in embedded systems. Embedded C supports I/O hardware operations and addressing, fixed-point arithmetic operations, memory/address space access, and various other features that are REQUIRED to develop fool-proof embedded systems. Following are the differences between traditional C language and Embedded C:
|
|||||||||