Interview Q & A

Interview QA



1. What is Recursion ? 
	A function calling to itself is called recursion. 
Some time stack may overflow if we are not properly exit the recursion function.
stack may overflow if the recursion function calling chain goes very long.
so the runtime error will occur.

ex:
main()
{
int sum;
sum=add(a,b);

}

add(int a, b)
{
int sum=0;
sum = a+b;
if (a>100)
return sum;

add();

}



2. What is stack overflow.?
	stack going outside its maximum range is called stack overflow.
say if stack size 1000 bytes, if the program is writing after 1000 bytes
memory reservered for stack is called stack overflow.
due to this runtime error will occur.



3. what is itoa() function?

  itoa() converts integer to character.

Ex: 
int x=222 
char buf[20]
iota(x,buf, 10); //decimal number to string
iota(x,buf, 2); //binary number to string
iota(x,buf, 16); //hexadecimal number to string


	
4. what is atoi() function?
  atoi function converts string to integer.

ex:
char str="32322";
num=atoi(str);



5. write your own funtion itoa(), atoi() ?



6. what is bigendian?

  	The  data present in the variable, if it stores Higher byte first in memory is called bigendian.
ex: var =0x44556677 

in memory it stores first 44 then --55 --66 --77
ex: 0xffff0000 = 44
    0xffff0001 = 55
    0xffff0002 = 66
    0xffff0003 = 77 



7. what is little endian?

  	The  data present in the variable, if it stores Lower byte first in memory is called little endian.
ex: var =0x44556677 

in memory it stores first 77 then --66 --55 --44

ex: 0xffff0000 = 77
    0xffff0001 = 66
    0xffff0002 = 55
    0xffff0003 = 44 



8. What is memory leak?
   If the memory is allocated using malloc, calloc etc after using it has to be freeed
if that memory is not used more.

if that memory is not freeed then it is called memory leakage.



9. Segmentation fault?
It is caused by the program writing and reading memory in illegal memory location is called segmentation fault.
say a read only location, or writing the non existing array element.
it causes the runtime error.



10. Dangling pointer?
   If a pointer is allocated a memory then after using it is deallocated. 
The pointer still pointing to the same meory location, but it is unreserved for it now.
if this pointer is accessed then unpredictable behavior accours, this is called dangling pointer .
it causes runtime error.



11. what is token?

each word say keyword, symbols, variables, ; , etc in a c program is called token.
there are 6 types of token
 
  - keywords  ex: int, float, switch, case, if, else etc
  - operators ex: +, -, *, /, %, |, &, ^, || etc
  - strings  ex: "sum = %d, avg= %f", "total = " 
  - Identifiers(ex. main, sum, total), 
  - Contants(ex, 44,67)
  - Special symbols (ex: (), {})



12. what is forward reference?

    Refering to the label before its declaration is called forward reference.


goto SUM;

SUM:
 ------
 -----