Interview QA – III

Interview QA - III



Ques 1. what are storage classes and their scope?

The storage classes in C are auto, Register, static, extern.

auto: Local variables are by default auto variables.
      auto variables stored in stack memory
      the scope of auto variables is local to the funtion, it exists till the 
      program control present in the function.
      It is used for local variables declaration.

Register: The scope of this variable is local to the function.
          The variable is stored in controller registers, if the registers are full then 
           the variables are converted into auto variable .
          The life is present till the program control present in the funtion where it is declared.
          It is used for loop variables, since it is stored in register accessing it is fast.

static: The scope of static variable is local to the funtion where it is declared. If the variable is
        declared global then its scope is only in the file where it is declared.
	It is stored in data memory.
	Its life is till the program running.

extern : It is used for the global variables. if we want to access the global varible declared in 
         another file we use extern storage classifier to access it.
         scope is through out the file where it is declared.
         it stores in data memory.
        

Ques 2. what are the features of c language?

The most important features of c languages are:
 - portability  - c language is platform indpendent language.
 - modularity   - the larger program can be break down into smaller programmes. 
 - flexibility  - the language is flexible to write os, compilers and embedded system programmes.
 - speed        - the c language compile and executes high speed compared with other high level languages.
 - extensibilty - the possibility to add new features to the program.



Ques 3. what are the basic data types associated with c language?
  - int - it is used to store numbers
  - float - it is for numbers with fractional part
  - char - it is used for stor
  - double - it is for double precision floating point representation.
  - void - special purpose type without any value.




Ques 4. what is structure padding and packing?

when a structure is declared integers take 4 bytes of memory,
The char came in between the integers then it also takes 4 bytes, the data stored in 1 byte remaining
bytes are garbage values stored and this is called padding.
So save the memory storage all ints and floats has to be declared serially then chars has to be declared. 

to occupy all the memory without leaving space in between then packing has to be done.
this done by declaring 
#pragma pack(1)

above main funtion.


Ques 5. what is dangling pointer?
	A pointer is declared and memory is allocated with malloc or calloc and then it is freed.
The pointer is still pointing to same memory, but memory is not reservered for it.
This type of pointer is called dangling pointer.


Ques 6. what is wild pointer in c?

If a pointer is declared but memory is not allocated. then it is pointing some memory. 
it is bad programming practice and it leads to bad programming practice. this ponter is called wild pointer.


Ques 7. what is prototype of a function?
	Prototype of a function is a declaration of a funtion with the following information to the controller.
	-- the return type of the function. 
	-- the input parameters to the funtion
        -- name of the function
	
	ex: int fun(char, float);

Ques 8. what is the differance between == and = ?
        = is an assignment.
	== is a equality checking operator it gives true or false status.


Ques 9. what is the cyclic nature of datatypes in c?
	If the value of the variable is goes beyond its range then the value change according to cyclic nature.
there is no compiler error for this. the data types int, char long supports this feature, and float and double
not supporting it.

ex:
     char ch=129;
 then ch=-127 this called cyclic in nature.
 since the range of character is -127  -- 0 -- 128.


Ques 10. what is nested loops in c?

executing loop inside another loop is called nested loops.
ex:
    for(i=0;i<5 ; i++)
    {      
      for(j=0; j<5; j++)
      {
      }
    }

Ques 11. what is break and continue statement in c?
	the on executing break statement the program control goes out of the loop or switch statement.
        on executing continue in a loop statement, the control goes to the beginning of the loop.
	
 for (i=0; i<5; i++)
  {
   if(y == 0)
      break;
   else
      z=x/y;
  if (z > 23)
   continue;
  }



Ques 12. How data is stored in stack?
	The data stored in stack is of the form FILO, first in last out. The data stored last is retreived first.
for storing we use push() operation, for retriving we use pop() function.


Ques 13. what { } indicates in c language?

	This { } curly brackets indicates the block of code start and end.
	It can be used in for , while, do while loops. it is also used in if, else, switch structures. 


Ques 14. how to generate random number in c?
 The random numbers can be generated using rand() function.

void main()
{
int a;
a=rand();
}


Ques 15. what is indirect reference in c?
 
	If a variable is declared as pointer then it is called indirect reference to the variable, 
we cannot access the variable directly. If the variable is declared then it can be accessed directly.