1.     What is the difference between declaration and definition?

Answer: Definition means where a variable or function is defined in reality and actual memory is allocated for variable or function.

Declaration means just giving a reference of a variable and function.

2.     What are the different storage classes in C?

Answer: AUTO, STATIC, EXTERN, REGISTER

auto is the default storage class for local variables.

{

int Count;

auto int Month;

}

register is used to define local variables that should be stored in a register instead of RAM This means that the variable has a maximum size equal to the register size (usually one word) and cannot have the unary ‘&’ operator applied to it (as it does not have a memory location).

                    {

                      register int  Miles;

                    }

Register should only be used for variables that require quick access – such as counters. It should also be noted that defining ‘register’ goes not mean that the variable will be stored in a register. It means that it MIGHT be stored in a register – depending on hardware and implementation restrictions.

static – Storage Class

static is the default storage class for global variables. The two variables below (count and road) both have a static storage class.

     static int Count;int Road;main(){printf(“%d\n”, Count);printf(“%d\n”, Road);}

‘static’ can also be defined within a function. If this is done, the variable is initalized at compilation time and retains its value between calls. Because it is initialized at compilation time, the initialization value must be a constant. This is serious stuff – tread with care.

     void Func(void){static Count=1;}

Here is an example

There is one very important use for ‘static’. Consider this bit of code.

     char *Func(void);main(){char *Text1;Text1 = Func();}char *Func(void){char Text2[10]=”martin”;return(Text2);}

‘Func’ returns a pointer to the memory location where ‘Text2’ starts BUT Text2 has a storage class of auto and will disappear when we exit the function and could be overwritten by something else. The answer is to specify:

     static char Text[10]=”martin”;

The storage assigned to ‘Text2’ will remain reserved for the duration if the program.

extern – storage Class

extern defines a global variable that is visable to ALL object modules. When you use ‘extern’ the variable cannot be initalized as all it does is point the variable name at a storage location that has been previously defined.

Source 1                                                                 Source 2

——–                                                                     ——–

extern int count;                                                     int count=5;

write()                                                                           main()

{                                                                                      {

printf(“count is %d\n”, count);                                   write();

}                                                                                       }

Count in ‘source 1’ will have a value of 5. If source 1 changes the value of count – source 2 will see the new value. Here are some example source files.

 3.     What is interrupt?

 Answer: Interrupts (also known as traps or exceptions in some processors) are a technique of diverting the processor from the execution of the current program so that it may deal with some event that has occurred. Such an event may be an error from a peripheral, or simply that an I/O device has finished the last task it was given and is now ready for another. An interrupt is generated in your computer every time you type a key or move the mouse. You can think of it as a hardware-generated function call.

 4.     What is Hardware Interrupt?

Answer: There are two ways of telling when an I/O device (such as a serial controller or a disk controller) is ready for the next sequence of data to be transferred. The first is busy waiting or polling, where the processor continuously checks the device’s status register until the device is ready. This wastes the processor’s time but is the simplest to implement. For some time-critical applications, polling can reduce the time it takes for the processor to respond to a change of state in a peripheral.

5.  What is Software Interrupt?

Answer: A software interrupt is generated by an instruction. It is the lowest-priority interrupt and is generally used by programs to request a service to be performed by the system software (operating system or firmware).

Difference between Hardware Interrupt and Software Interrupt

An interrupt is a special signal that causes the computer’s central processing unit to suspend what it is doing and transfers its control to a special program called an interrupt handler. The responsibility of an interrupt handler is to determine what caused the interrupt, service the interrupt and then return the control to the point from where the interrupt was caused. The difference between hardware interrupt and software interrupt is as below:

Hardware Interrupt: This interrupt is caused by some external device such as request to start an I/O or occurrence of a hardware failure.

Software Interrupt: This interrupt can be invoked with the help of INT instruction. A programmer triggered this event that immediately stops execution of the program and passes execution over to the INT handler. The INT handler is usually a part of the operating system and determines the action to be taken e.g. output to the screen, execute file etc.

Thus a software interrupt as it’s name suggests is driven by a software instruction and a hardware interrupt is the result of external causes.