Hi Students,
Every one very curious about the interview questions because you don’t know what type of questions Recruiter will ask so our embedded training institute in Bangalore is offering top 10 questions for students who are eager to get a job in the embedded field. With Professional Training Institute, You can get embedded system training which is 100% practical based training so you can get a place soon. Here see top 10 interview question in the embedded system.
Beginner level (Fresher)
Volatile is the keyword used for optimization by the compiler during code compilation. We are conveying the message to the compiler “Hey look this pieces of code can be modified externally so don’t optimized this code associated with the current variable”
Examples:
Int main()
{
Int volatile vari=1;
Int Baudrate;
While (vari==1)
{
Baudrate = 9600;
}
}
If we did not make “vari” as volatile then compiler will remove this while loop as the value of “vari” is not going to change anywhere in the program.
Mid-Level (Experience less than 5 years):
Volatile was mainly introduced for the compiler to help in decision taking for code optimization. Until we are using C as application programming there is no impact of Volatile keyword, but as soon as we start handling with Peripheral like timer, ADC, I2C, RTC, IO port, Interrupt service routines(ISRs) then volatile is a most important keyword.
I am sure many times/some time you may face any of below conditions
1) When optimization is off, the code works fine but as soon as optimization is on code give some random error. In some compiler, we are having a different level of optimization. Therefore, up to certain level code works beyond that code gives an error.
2) Sometimes as soon as we start using Interrupt then some random error is generating.
3) In multitasking, system individual task works correctly but multiple tasks together give a problem.
So now consider below example
“static volatile sig_atomic_t signo[_NSIG];”
Here word static is defining the scope of the variable, while word volatile is giving instruction to the compiler that doesn’t optimize the code.
Please note volatile does not control or change the storage class of variable. While static keyword controls the storage class.
In another example
const volatile char *PORTA = (const volatile char *) 0x50;
Here we are saying that PORTA is defined at address 0x50, asking compiler not to optimized below code, at the same time by using const we are removing any by mistake writing by the user.
PORTA=0xFF
While (PORTA == 0xFF)
//do something here
While (PORTA!=0xFF)
Signal_received++;
If we did not make PORTA as the volatile compiler will optimized II while loop as he will think I while loop will never fail.
Const means if we write by mistake below the line.
PORTA= 0x55; – Compiler itself will give error.
Senior Level (More than 5 years):
A senior person can include few of above points and refer below advance information.
“An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine.”
The line is taken from C-Open standard. Which clearly says that the volatile keyword should be implemented as an abstract machine. Which clearly means compiler can’t change anything, compiler need to convert C code as it is in
executable.
You can refer “ISO/IEC 9899: TC3” for more information.
The const keyword makes sure that the value of the variable declared as constant can’t be changed. This statement holds true in the scope of the full program. So if by mistake user tried to write on const variable compiler itself will give the error, and say read-only variable can’t change.
Since variable can’t change anywhere in the code the compiler will be tried to the optimized code associated with this variable, the compiler may think this code will not change in current
scope.
So the word volatile is the instruction to the compiler, look compiler although variable is not changing in current scope, it can change from any other unknown factors (Like IO operations, Switch operation, ISR, other Task etc.) so don’t optimize.
What is a Static variable? Any variable we can analyze in two ways
A) Scope.
B) Life.
A) The scope of static variable –
1) If the variable is defined in local scope (Means inside of any function, may be either main or any other function), then the scope of static variable will be within a function.
2) If a static variable is defined in global scope (Means not inside any function) then the scope of the variable will be within the file. In the same file, any function can use this variable.
B) Life of scope variable –
1) Life of static variable is throughout the program. No matter it is defined in the local scope or global scope.
Storage class of static variable is Data segment, not stack. Let’s understand this. All local variables are stored in the stack, the stack is RAM memory which is used for temporary storage, all local variable of the function is stored here STACK and once we exit from that function this memory get free. So it means once we exit from function all local
variable has died. But if we want to preserve our variable even after the exit from the function, so that when next time we enter into the same function we should get same old value, in this case, we can define a variable as a STATIC variable.
This property is used for when with the same name we have interface other functionality then we can make functions with static scope, and other files also can have a function with the same. While the wrapper function will call the local static function.
Life of both variables (static variable and global) is throughout the program. Here understand question carefully. Questions are asking global static variable. It means is variable is saved in the file scope. Within file any function can use that variable, this variable will not be available in any other files.
While global variable can be accessed through any file.
The interview you can start giving an answer from here – In practical we need a combination of above data types, few examples are
1) Collecting student information
2) Collecting patient information
3) CAR information to be saved. Like this many examples is possible.
If we save information in system-defined data types, it will be difficult to manage them as all those data will be saved in a different – different memory location. C language is having provision to save all required information one
place. It is called a user-defined data type.
Structure and union are user-defined data type which stored data collectively. See below example
struct time{
unsinged int MemRead;
char sec;
char min;
char hour;
};
The structure will be saving all its parameters in memory like this
The structure will reserve memory for each of these elements; it will take 4 bytes each char will take 1 byte. The good part is all variable is stored in a contiguous memory location.
We can make a variable from a structure like this
Struct time today_time;
Union – as the name suggests it will be the union of all collected data into it. It means the total memory allocated to the union variable is the maximum size of the variable. See in below
example
union time{
unsinged int MemRead ;
char sec;
char min;
char hour;
};
So all three variable sec, min, hour will be saved into the same place. Many students ask us, what is the use of a union.
Structure and union together can make magic lets below example.
union time{
unsinged int MemRead;
struct time_segment{
char sec;
char min;
char hour;
char day;
}st_time;
}un_time;
Now see how this union will be seating into memory.
Now when we read from memory we can read like this
un_time.MemRead = 0x01020304;
while using we can use like this
if (un_time.st_time.day ==5)
{
Printf(“today is holiday\n”);
}else{
Printf(“today is working\n”);
}
So hope it making sense, a combination of union and structure is an amazing thing to use. This is most widely used in the embedded system, see our other post which is having details description of union and structure.
Declare a function pointer which will take two int pointer as input and return a char pointer
char * (*foo)(int *a, int *b);
Declare a function pointer, which will return the function pointer structure pointer and accepts one character and one integer.
struct school* (*foo)(char a, int b);
we can also have an array of structure pointers like this
char * (*foo[5])(int *a, int *b);
this can save 5 address of functions. Like this
char * (*foo[5])(int *a, int *b) = {add, sub, mul, div, mod};
so when we can use an array of function pointer like this
for(i=0;i<=5;i++)
{
foo[i](5,3);
}
Size of integer pointer and character is 8 bytes on a 64-bit machine and 4 bytes on32-bit machine. Size of pointers does not depend upon the type of parameters, because pointer needs to save memory address, it does not matter what we are going to save them or from that address who many bytes we want. We just need to save the address.
Interrupt latency should be as minimum as possible, otherwise, some very important action may miss, this delay in execution may cause some big impact on system performance.
In the bottom half of ISR, we are executing out of ISR, we keep monitoring the flag signal sent by top half. Once execution is completed in bottom half we clear the flags and waits for next interactions from system or ISR.
With this method, we occupy very less time in the ISR. So other interrupts can be executed faster than previous, this reduces interrupt latency.
In C language we are having many system-defined data types like int, char, float, double etc. Size of each one is fixed like it is 4 bytes, char is one byte, the float is 4 bytes etc.
We are also having user-defined data types like struct, union. Here we struct reserve memory for each of its elements while union reserve memory for the highest data types.
We can also make an array like int dates[100], it will reserve 100*4 = 400 bytes in the memory. The same way we can have struct school mycityschool[50]. This will reserve size of memory = size of one structure * 50
All above data types reserve memory at the compile time. It means how much element we need we have decided at the time of compilation time itself. But in many practical conditions, we may not how many students will join today, or how many cars will be sold today, or how many patients will come today in the hospital.
So it means we can’t decide the size of at the time of compilation. We need to wait in real time use. Some need some method by which we can allocate memory on runtime. This type of memory allocation is called dynamic memory allocation.
An example is here:
Ptr = (int *) malloc (sizeof (int)*50). This malloc will reserve memory of total 4*50= 200 bytes into memory and return void pointer. Before using this we need to do typecast like (int *) and then we can use ptr memory of int array of 50 elements.
We can use malloc in run time to save any number of data we want, off-course memory should be available. What is the meaning of the above sentence?
It means the system is allocating memory from some reserved memory space this reserve memory space is called as HEAP memory. This is a section of memory which is used in dynamic memory allocation. Once use of memory is complete then we should make it free like this
Free (ptr); this will release memory to the system again and can be reused.
We are having one more point to discuss here. Malloc is just reserve memory, it won’t change contains memory. But in some application, we may need memory with initializing with 0 In that case either we reserve memory with the malloc and through memcpy we make the initialize with 0, Or we can use
Ptr = (int *) Calloc (number_of_element, size_of_each_element);
Here we have to give two input one is a number of the element, size of each element.
Ptr =(int *) calloc (50, sizeof(int));
This will reserve 50*4 bytes and initialize withzero also.
We are confident with our skill and capability, come and join our one-month free demo class we are sure you will fall in love with our teaching methods.
Best of luck for your future.
Professional Training Institute.
More Tags: embedded training in Bangalore | embedded Linux training in Bangalore | best-embedded training institute in Bangalore | embedded training institute in Bangalore | list of embedded systems institute in Bangalore | embedded systems courses in Bangalore | embedded courses in Bangalore
Every one very curious about the interview questions because you don’t know what type of questions Recruiter will ask so our embedded training institute in Bangalore is offering top 10 questions for students who are eager to get a job in the embedded field. With Professional Training Institute, You can get embedded system training which is 100% practical based training so you can get a place soon. Here see top 10 interview question in the embedded system.
Top 10 Interview Questions by Embedded Training Institute in Bangalore
1) What is the use of the volatile keyword?
I will answer this question in three levelBeginner level (Fresher)
Volatile is the keyword used for optimization by the compiler during code compilation. We are conveying the message to the compiler “Hey look this pieces of code can be modified externally so don’t optimized this code associated with the current variable”
Examples:
Int main()
{
Int volatile vari=1;
Int Baudrate;
While (vari==1)
{
Baudrate = 9600;
}
}
If we did not make “vari” as volatile then compiler will remove this while loop as the value of “vari” is not going to change anywhere in the program.
Mid-Level (Experience less than 5 years):
Volatile was mainly introduced for the compiler to help in decision taking for code optimization. Until we are using C as application programming there is no impact of Volatile keyword, but as soon as we start handling with Peripheral like timer, ADC, I2C, RTC, IO port, Interrupt service routines(ISRs) then volatile is a most important keyword.
I am sure many times/some time you may face any of below conditions
1) When optimization is off, the code works fine but as soon as optimization is on code give some random error. In some compiler, we are having a different level of optimization. Therefore, up to certain level code works beyond that code gives an error.
2) Sometimes as soon as we start using Interrupt then some random error is generating.
3) In multitasking, system individual task works correctly but multiple tasks together give a problem.
So now consider below example
“static volatile sig_atomic_t signo[_NSIG];”
Here word static is defining the scope of the variable, while word volatile is giving instruction to the compiler that doesn’t optimize the code.
Please note volatile does not control or change the storage class of variable. While static keyword controls the storage class.
In another example
const volatile char *PORTA = (const volatile char *) 0x50;
Here we are saying that PORTA is defined at address 0x50, asking compiler not to optimized below code, at the same time by using const we are removing any by mistake writing by the user.
PORTA=0xFF
While (PORTA == 0xFF)
//do something here
While (PORTA!=0xFF)
Signal_received++;
If we did not make PORTA as the volatile compiler will optimized II while loop as he will think I while loop will never fail.
Const means if we write by mistake below the line.
PORTA= 0x55; – Compiler itself will give error.
Senior Level (More than 5 years):
A senior person can include few of above points and refer below advance information.
“An object that has volatile-qualified type may be modified in ways unknown to the implementation or have other unknown side effects. Therefore any expression referring to such an object shall be evaluated strictly according to the rules of the abstract machine.”
The line is taken from C-Open standard. Which clearly says that the volatile keyword should be implemented as an abstract machine. Which clearly means compiler can’t change anything, compiler need to convert C code as it is in
executable.
You can refer “ISO/IEC 9899: TC3” for more information.
2) Can a variable be both const and volatile?
This question is already answered above but in short discuss again.The const keyword makes sure that the value of the variable declared as constant can’t be changed. This statement holds true in the scope of the full program. So if by mistake user tried to write on const variable compiler itself will give the error, and say read-only variable can’t change.
Since variable can’t change anywhere in the code the compiler will be tried to the optimized code associated with this variable, the compiler may think this code will not change in current
scope.
So the word volatile is the instruction to the compiler, look compiler although variable is not changing in current scope, it can change from any other unknown factors (Like IO operations, Switch operation, ISR, other Task etc.) so don’t optimize.
3) What is a static variable? Or what is a static keyword?
Both questions are look’s like same but they are different, let’s analyze carefullyWhat is a Static variable? Any variable we can analyze in two ways
A) Scope.
B) Life.
A) The scope of static variable –
1) If the variable is defined in local scope (Means inside of any function, may be either main or any other function), then the scope of static variable will be within a function.
2) If a static variable is defined in global scope (Means not inside any function) then the scope of the variable will be within the file. In the same file, any function can use this variable.
B) Life of scope variable –
1) Life of static variable is throughout the program. No matter it is defined in the local scope or global scope.
Storage class of static variable is Data segment, not stack. Let’s understand this. All local variables are stored in the stack, the stack is RAM memory which is used for temporary storage, all local variable of the function is stored here STACK and once we exit from that function this memory get free. So it means once we exit from function all local
variable has died. But if we want to preserve our variable even after the exit from the function, so that when next time we enter into the same function we should get same old value, in this case, we can define a variable as a STATIC variable.
What is the static keyword in C?
To answer this question you to include all the above points and as well as this static keyword can be applied to function. When any function is defined static then the function will be available into the same file. Other files can’t use that function.This property is used for when with the same name we have interface other functionality then we can make functions with static scope, and other files also can have a function with the same. While the wrapper function will call the local static function.
4) What is the difference between a global static variable and a global variable?
The scope of the global variable is throughout the program, while the scope of a static variable is within the file.Life of both variables (static variable and global) is throughout the program. Here understand question carefully. Questions are asking global static variable. It means is variable is saved in the file scope. Within file any function can use that variable, this variable will not be available in any other files.
While global variable can be accessed through any file.
5) What is the difference between structure and union?
C language is having many system-defined data types like char, int, float, double, long etc. we are also having an array of the above data types, which will help us to save more than many variables in contiguous locations.The interview you can start giving an answer from here – In practical we need a combination of above data types, few examples are
1) Collecting student information
2) Collecting patient information
3) CAR information to be saved. Like this many examples is possible.
If we save information in system-defined data types, it will be difficult to manage them as all those data will be saved in a different – different memory location. C language is having provision to save all required information one
place. It is called a user-defined data type.
Structure and union are user-defined data type which stored data collectively. See below example
struct time{
unsinged int MemRead;
char sec;
char min;
char hour;
};
The structure will be saving all its parameters in memory like this
The structure will reserve memory for each of these elements; it will take 4 bytes each char will take 1 byte. The good part is all variable is stored in a contiguous memory location.
We can make a variable from a structure like this
Struct time today_time;
Union – as the name suggests it will be the union of all collected data into it. It means the total memory allocated to the union variable is the maximum size of the variable. See in below
example
union time{
unsinged int MemRead ;
char sec;
char min;
char hour;
};
So all three variable sec, min, hour will be saved into the same place. Many students ask us, what is the use of a union.
Structure and union together can make magic lets below example.
union time{
unsinged int MemRead;
struct time_segment{
char sec;
char min;
char hour;
char day;
}st_time;
}un_time;
Now see how this union will be seating into memory.
Now when we read from memory we can read like this
un_time.MemRead = 0x01020304;
while using we can use like this
if (un_time.st_time.day ==5)
{
Printf(“today is holiday\n”);
}else{
Printf(“today is working\n”);
}
So hope it making sense, a combination of union and structure is an amazing thing to use. This is most widely used in the embedded system, see our other post which is having details description of union and structure.
6) What is the function pointer, write delectation (prototype of the following function pointer)?
A function pointer is a variable, which can hold the address of the function. This is used in callbacks. Since C is sequential language. It processes one by one. However, for some cases, we may need to call a function based on conditions. In C a function pointer can only achieve this.Declare a function pointer which will take two int pointer as input and return a char pointer
char * (*foo)(int *a, int *b);
Declare a function pointer, which will return the function pointer structure pointer and accepts one character and one integer.
struct school* (*foo)(char a, int b);
we can also have an array of structure pointers like this
char * (*foo[5])(int *a, int *b);
this can save 5 address of functions. Like this
char * (*foo[5])(int *a, int *b) = {add, sub, mul, div, mod};
so when we can use an array of function pointer like this
for(i=0;i<=5;i++)
{
foo[i](5,3);
}
7) What is size of character, integer, integer pointer, character pointer?
The size of a character is 1 byte. Size of an integer is 4 bytes.Size of integer pointer and character is 8 bytes on a 64-bit machine and 4 bytes on32-bit machine. Size of pointers does not depend upon the type of parameters, because pointer needs to save memory address, it does not matter what we are going to save them or from that address who many bytes we want. We just need to save the address.
8) What is interrupt latency?
Interrupt latency is the time required for an ISR responds to an interrupt. When interrupts occur in the embedded system, then the processor finishes current instruction, save the value of the program counter and jump to the required ISR. Sometime if the processor is busy and serving another interrupt then another interrupt may be pending till processor/controller is gets free from current ISR. Until that time another interrupt has to wait, this is the interrupt latency.Interrupt latency should be as minimum as possible, otherwise, some very important action may miss, this delay in execution may cause some big impact on system performance.
9) How to reduce interrupt latency?
In order to reduce interrupt latency, while designing the system we should take a minimum time as possible in the ISR. We should divide our ISR into two part, The top half and bottom half. Top half should be very small and control should come out as soon as possible, normally in this section, we just copy the data, and generate some flags.In the bottom half of ISR, we are executing out of ISR, we keep monitoring the flag signal sent by top half. Once execution is completed in bottom half we clear the flags and waits for next interactions from system or ISR.
With this method, we occupy very less time in the ISR. So other interrupts can be executed faster than previous, this reduces interrupt latency.
10)What is the dynamic memory allocation? Where we can use this?
The dynamic memory allocation is one of the best features in of C language. Let’s see in details,In C language we are having many system-defined data types like int, char, float, double etc. Size of each one is fixed like it is 4 bytes, char is one byte, the float is 4 bytes etc.
We are also having user-defined data types like struct, union. Here we struct reserve memory for each of its elements while union reserve memory for the highest data types.
We can also make an array like int dates[100], it will reserve 100*4 = 400 bytes in the memory. The same way we can have struct school mycityschool[50]. This will reserve size of memory = size of one structure * 50
All above data types reserve memory at the compile time. It means how much element we need we have decided at the time of compilation time itself. But in many practical conditions, we may not how many students will join today, or how many cars will be sold today, or how many patients will come today in the hospital.
So it means we can’t decide the size of at the time of compilation. We need to wait in real time use. Some need some method by which we can allocate memory on runtime. This type of memory allocation is called dynamic memory allocation.
An example is here:
Ptr = (int *) malloc (sizeof (int)*50). This malloc will reserve memory of total 4*50= 200 bytes into memory and return void pointer. Before using this we need to do typecast like (int *) and then we can use ptr memory of int array of 50 elements.
We can use malloc in run time to save any number of data we want, off-course memory should be available. What is the meaning of the above sentence?
It means the system is allocating memory from some reserved memory space this reserve memory space is called as HEAP memory. This is a section of memory which is used in dynamic memory allocation. Once use of memory is complete then we should make it free like this
Free (ptr); this will release memory to the system again and can be reused.
We are having one more point to discuss here. Malloc is just reserve memory, it won’t change contains memory. But in some application, we may need memory with initializing with 0 In that case either we reserve memory with the malloc and through memcpy we make the initialize with 0, Or we can use
Ptr = (int *) Calloc (number_of_element, size_of_each_element);
Here we have to give two input one is a number of the element, size of each element.
Ptr =(int *) calloc (50, sizeof(int));
This will reserve 50*4 bytes and initialize withzero also.
Choose the Best Embedded Training Institute in Bangalore
We are a Professional Training Institute provides complete hands-on practical training in the embedded system, if you looking for embedded system training in Bangalore then choose us, as you go through our review and check what our old student is saying, they believe we are top embedded institute in Bangalore.We are confident with our skill and capability, come and join our one-month free demo class we are sure you will fall in love with our teaching methods.
Best of luck for your future.
Professional Training Institute.
More Tags: embedded training in Bangalore | embedded Linux training in Bangalore | best-embedded training institute in Bangalore | embedded training institute in Bangalore | list of embedded systems institute in Bangalore | embedded systems courses in Bangalore | embedded courses in Bangalore