-->

Tuesday, October 21, 2014

Interview Question

Question 1 :What is the difference between macros and inline functions?

 Ans : 

 Macro- does not involve in compilation if there is any logical error also just replaces the code.

Inline- look like function, but control doesn't goes to function and execute, it simply replaces the code like macro but involves in compilation. 

Question 2:Difference between structure and union? 


 Ans : 

   Union allocates the memory equal to the maximum memory required by the member of the union but structure allocates the memory equal to the total memory required by the members

Question 3:Memory Model In C?
  
Ans :

In c There are six type of memory model available.
These Memory Models are:-
1.Tiny
2.Small
3.Medium
4.Compact.
5.Large.
6.Huge.
 


Question 4:What is Dangling Pointer?

If any Pointer is pointing to memory address of any variable but after some variable has deleted from the memory location.but while such a pointer is pointing that memory location...

Such pointer is known as "Dangling Pointer"....And this Problem is known as "Dangling Pointer Problems"...
 


#include<stdio.h>
int *val() ;
void main(void)
{
int *p; //wild pointer
p=val();
printf("%d",*p);
getch();
}
int *val()
{
int x=25;
x++;
return &x;

}


Question 5:Void Pointer and Generic Pointer

When a variable is declared as being a pointer to type void it is known as a generic pointer. Since you cannot have a variable of type void, the pointer will not point to any data and therefore cannot be dereferenced.

It is still a pointer though, to use it you just have to cast it to another kind of pointer first. Hence the term Generic pointer.

This is very useful when you want a pointer to point to data of different types at different times.
 


Question 6:Inline and macros are same?

Ans: No

No inline is not same as macro definition, as macro is preproccessed but inline is just the indication to the compiler to put the whole body of the function where it is called.  

Putting inline keyword before any function definition is just the indication or request , compiler is free to choose whether it's going to make that function inline or leave it as normal 


Question 7: What is the usage of Function Pointer?

 Ans:
 Function Pointer Mainly Used in Callback Function,generic qsort,In Dynamically Run time binding,Interrupt Handling,Timer Event etc

Question 8: Exactly what does static variable indicate?

 Ans:
 There are actually three major purposes of the static.

      1. If you declare inside a function:
           It keeps the value between function calls

      2.If it is declared for a function name: 
           By default function is actually extern therefore it is going to be visible from all other files ..
 
          if the function declaration is as static..it is invisible for the external files.

      3. Static for global variables:
         By default we are able to make use of the global variables from outside files when it is static global..that variable is restricted to with in the file.

Question 9: Steps taken in servicing an interrupt?

Ans:Upon the triggering of an interrupt the following sequence is followed by the microcontroller providing that the both the specific interrupt and global interrupts are enabled in the microcontroller:

1.The microcontroller completes the execution of the current instruction, clears the I bit and stores the address of the next instruction that should have been executed (the content of the PC) on the stack.

2.The interrupt vector of the triggered interrupt is then loaded in the PC and the microcontroller starts execution from that point up until is reaches a RETI instruction.

3.Upon the the execution of the RETI instruction the address that was stored on the stack in step 1 is reloaded in the PC and the I bit is re-enabled.

4.The microcontroller then start executing instructions from that point. That is the point that it left off when the interrupt was triggered. 
  

























 

No comments:

Post a Comment

Receive Our Quality Tutorials Straight In Your Inbox By Submitting Your Email ID Below...

Your Information Will Never Be Shared.