Monday, August 13, 2012

Frequently Asked C Interview Questions With Answers-2

Here, are some sample questions based on “C Programming language”. Read it carefully as these questions will help you in cracking any interview.


Question -6) What is scope & storage allocation of extern and global variables?

Extern variables are global variables. These variables belong to the external storage class and are stored in the system’s main memory. They are declared in a separate source file which could be outside the current program scope. The scope of these variables is global.

Global variables are variables declared above the main function. They are accessible throughout the program. They have 0 as the default value.


Question -7) What is scope & storage allocation of register?

Register variables are storage allocated in the CPU registers. Since they are stored in the CPU registers, their storage and accessibility is much easier and faster than other variables. The scope of register variables is local to the blocks in which they are defined.


Question -8) What is scope & storage allocation of static and local variables?

The storage allocation of static variables is done at the beginning of program execution. After the program terminates, the memory is reallocated. Scope of static variables is local to the block within which they are defined.

Local variables are variables defined within a function or program. Their default value is a garbage value and they are accessed only by the particular function or program.


Question -9) What is the difference between 'break' and 'continue' statements?

The break keyword is used to terminate a loop or exit from a block. After exiting, the program control jumps to the statement after the loop or block.

The continue keyword is used to skip a current iteration and move to the next iteration.


Question -10) What is the difference between uses of 'for' and 'while' loops?

When a user wants to initialize, check condition and increment or decrement the value of a variable in a single statement, and using an iterative loop, then the loop used may be for loop.

When the user wants to initialize, check condition and increment or decrement value not using a single iterative loop, then he/she may use the while loop. Only one condition can be checked using the while loop.

2 comments:

Related Posts Plugin for WordPress, Blogger...