© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

C and C++ Interview Questions

16. What is the quickest searching method to use?
Ans:

A binary search, such as bsearch() performs, is much faster than a linear search. A hashing algorithm can provide even faster searching. One particularly interesting and fast method for searching is to keep the data in a digital trie. A digital trie offers the prospect of being able to search for an item in essentially a constant amount of time, independent of how many items are in the data set.
A digital trie combines aspects of binary searching, radix searching, and hashing. The term digital trie refers to the data structure used to hold the items to be searched. It is a multilevel data structure that branches N ways at each level.

Ex - 1: In the following pgm add a  stmt in the function  fun such that the address of 'a' gets stored in 'j'.
main(){
  int * j;
  void fun(int **);
  fun(&j);
 }
 void fun(int **k) {
  int a =0;
  /* add a stmt here*/
 }
Ans:
            *k = &a
Explanation:
The argument of the function is a pointer to a pointer.

Ex - 2: Find the output for the following C program
void main()
{
      int k=ret(sizeof(float));
      printf("\n here value is %d",k++);
}
int ret(int ret)
{
      ret += 2.5;
      return(ret);
}
Ans:
 Here value is 6
Explanation:

      The int ret(int ret), ie., the function name and the argument name can be the same. Firstly, the function ret() is called in which the sizeof(float) ie., 4 is passed,  after the first expression the value in ret will be 6, as ret is integer hence the value stored in ret will have implicit type conversion from float to int. The ret is returned in main() it is printed k after do the post increment.


SLogix Student Projects
bottom