Embedded using C Interviews Questions and Answers
What is Embedded system? Describe Embedded C.
In simple words, Embedded system can be referred as customise hardware with customise software. Embedded systems are controller based which is embed with software to perform specific task.
Embedded C is extended version of C language which is used to develop micro- controller based systems.
What are little endian and big endian types of storage? How can you identify which type of allocation a system follows?
Big endian and little endian are two formats to store multibyte data types into computer’s memory. Big endian format and little endian format. In Big endian format msb(most significant byte) gets memory first and lsb (least significant byte) in last.
In case of little endian format the lsb byte gets memory first and msb byte in last.
Suppose an integer having value 0x12345678.
In case of big endian 0x12 gets stored first in memory, then 0x34 ,then 0x56 and in the last 0x78.
In case of little endian 0x78 gets stored first in memory, then 0x56 ,then 0x34 and in the last 0x12.
|Big Endian Format|
|Little Endian Format|
Write a C program to identify little and big endian.
int main ()
unsigned int x = 0x12345678;
char *c = (char*) &x;
if (*c == 0x78)
printf (“Architecture is little endian. \n“);
What is ISR?
ISR refers to Interrupt service routine.Whenever an interrupt occurs, the controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine.This process is also known as interrupt handler.
What is qualifier in C?
Qualifiers are the keywords which are used to modify the values of variables. There are two types of qualifier in C.
Const qualifier used with variable when we want to make variable to unchangeable. If you will try to change, compiler will give you error.
Variable qualified with volatile prevent the compiler to optimize that variable. Values of variable can be changed by code outside the scope of current code at any time.The system always reads the current value of a volatile object from the memory location rather than keeping its value in temporary register.
What is a ‘volatile’ variable, can variable be both constant and volatile, can a pointer be volatile ?
Consider the following example:
volatile int x;
When compiler finds the variable qualified with volatile qualifier, it is clearly comes to know to compiler that it will not be involved in any changing related to variable. The value of this variable can be changed anytime by any external source.
A single variable can be const as well as volatile.Example
int volatile *const y;
y is a constant pointer to a volatile integer.
Yes, volatile pointers are possible in c.
int *volatile value;
What is interrupt latency? How to reduce interrupt latency?
Whenever microcontroller receives any interrupt, first it complete currently executing instruction , then provide service to interrupt and again continues the executing instruction from the same position where controller skipped .
So, it takes some time to microcontroller to provide service to interrupt. The amount of time(Number of cycle) taken by microcontroller to start servicing to interrupt known as interrupt latency.
Interrupt latency can be minimized by writing short ISR routine and by not delaying interrupts for more time.
Can we use any function inside the ISR?
Yes, we can but doing so will increase interrupt latency. That’s why it is not recommended as in many cases latency should be as small as possible and using function inside the ISR will also decrease performance.
What are storage classes?
Storage classes used to classify variable as per their scope (visibility) and lifetime. Default value and storing value place also differ to each other. There are four types of storage classes.
|Auto||Local||Within the function||Garbage value|
|register||Local||Within the function||Garbage value|
|Static||Local||Till the end of the program||Zero|
|extern||Global||Till the end of the program||Zero|
Note: Only register variables get memory in CPU register (if CPU register has vacant memory). Other three variables get memory in RAM memory locations.
What is use of static keyword?
Static keyword can be used with variable as well as functions. The life of static variable lasts till the end of the programs and scope is local(Visible within the function only). Still static variable holds their value after they are out of their scope.
static int count = 0;
printf(“%d “, increment());
printf(“%d “, increment());
Output: 1 2
Function with static within any source file can accessible to only that source file.By using static we make function local only to source file within it is defined.
What is use of register storage class?
In register storage class cpu registers are used to store values.
for example. If you want to store variable which will be frequently require then you can store it in register like in case of loops.However it is not guaranteed that variable will get store in register.
It is like request to cpu to allow the variable to store in CPU’s register.
If CPU has vacant register to store variable ,it permits otherwise ignore the request and variable gets allocated in ram memory.
Note: We cannot obtain the address of a register variable using pointers.
What is Synchronous and asynchronous data transmission?
Serial data communication has two types.
Synchronous data transmission
Synchronous transmission needs a clock signal between the source and target to let the target know of the new byte.synchronous transmission data is transmitted in the form of data bundles. So data rate of it very high.
Asynchronous data transmission
Asynchronous transmission has no need of clock signal between the source and target. It sends start and stop bit to start and stop the transmission.It send single byte data at a time so data rate of it is not much good.
Synchronous vs. Asynchronous Transmission
- In synchronous mode data is transmitted in bundle but in asynchronous mode data is transmitted byte by byte.
- Synchronous required a clock signal between the source and destination to acknowledge the destination about information while in asynchronous clock signal is not required.
- Data transfer rate of synchronous is faster compared to asynchronous .
- Synchronous mode has lower overhead compared to asynchronous transmission.
What is Baud Rate? How it is differ from Bit Rate?
In data communication, data are transferred along with signal. The number of signal transferred per second is known is Baud rate. Bite rate is number of bits (data) transferred per second. As a single signal may contain more than 1 bit while transferring the data. The relation between two is given below.
Bit rate = baud rate x the number of bit per baud
What is memory leak ?How we can avoid it?
Memory leak is a condition where programmer allocate memory in heap area by using dynamic memory allocation and forget two deallocate it.So, it is recommended to use free() function to deallocate memory which is allocated by dynamic memory allocation once the use of memory location is not further needed.
How to set, clear and toggle a single bit of variable?
Value represent initial variable and position represents the position of bit in variable.
Setting a Bit:
Value |= (1 << position)
Clearing a Bit:
Value &= ~ (1<<position)
Toggling a Bit:
Value ^= (1 << position)
What is Dynamic Memory Allocation(DMA)? What is difference between malloc() and calloc()?
Dynamic memory allocation (DMA) is process of allocation memory for variables at run time of program. This kind of allocation allocates memory in heap area of memory.
malloc function takes one argument at calling but calloc takes two arguments. Also memory allocated by calloc is initialized with zero.
These function always return pointer of type void which can be cast into a pointer of any form.
Syntax: For 5 element of int type variable. ptr is int type pointer.
ptr = (int *) malloc (5*sizeof(int))
ptr = (int*) calloc (5, sizeof(int))
What is void pointers in C?
Void pointer also known as generic pointers. There is no data type associated with these, so these can be typed cast to any types.
What is dangling pointer?
A pointer pointing to deleted or deallocated memory location is known as dangling pointer. To try to access this type of pointer causes undefined behaviour or segmentation fault.
What is wild pointer?
An uninitialized pointer known as wild pointer. When we declare any pointer without giving any address, it shows an arbitrary memory location. As we assign it a memory location, it is not a wild pointer any more.
int* ptr; //Wild pointer
ptr = &a; //Not more wild pointer
Explain the meaning of these pointers?
- int *ptr;
- cons int * ptr;
- int * const ptr;
- const int *const ptr;
It is a pointer to a variable. We can change the value pointer pointing to and also the value of ptr.
const int * ptr
It is pointer to a constant. It can be also declare as int const *ptr. We can change pointer to point other variable but we can not change the value of it by using pointer.
int * const ptr
It is constant pointer to a variable. We can change the value of variable by using pointer but we can not change pointer to point other variable.
const int *const ptr
It is constant pointer to a constant variable. Neither we can change pointer to point other variable nor we can change the value using pointer.