• +91 9723535972
  • info@interviewmaterial.com

C Interview Questions and Answers

C Interview Questions and Answers

Question - 131 : - Why should I prototype a function?

Answer - 131 : - A function prototype tells the compiler what kind of arguments a function is looking to receive and what kind of return value a function is going to give back. This approach helps the compiler ensure that calls to a function are made correctly and that no erroneous type conversions are taking place.

Question - 132 : - What is the quickest searching method to use?

Answer - 132 : - 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.

Question - 133 : - What are the advantages of auto variables?

Answer - 133 : - 1)The same auto variable name can be used in different blocks 2)There is no side effect by changing the values in the blocks 3)The memory is economically used 4)Auto variables have inherent protection because of local scope

Question - 134 : - What are the characteristics of arrays in C?

Answer - 134 : - 1) An array holds elements that have the same data type 2) Array elements are stored in subsequent memory locations 3) Two-dimensional array elements are stored row by row in subsequent memory locations. 4) Array name represents the address of the starting element 5) Array size should be mentioned in the declaration. Array size must be a constant expression and not a variable.

Question - 135 : - How do you print only part of a string?

Answer - 135 : - /* Use printf() to print the first 11 characters of source_str. */ printf(First 11 characters: ‘%11.11s’n, source_str);

Question - 136 : - In C, what is the difference between a static variable and global variable?

Answer - 136 : - A static variable declared outside of any function is accessible only to all the functions defined in the same file (as the static variable). However, a global variable can be accessed by any function (including the ones from different files).

Question - 137 : - In C, why is the void pointer useful?

Answer - 137 : - When would you use it? The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.

Question - 138 : - What is Polymorphism ?

Answer - 138 : - 'Polymorphism' is an object oriented term. Polymorphism may be defined as the ability of related objects to respond to the same message with different, but appropriate actions. In other words, polymorphism means taking more than one form. Polymorphism leads to two important aspects in Object Oriented terminology - Function Overloading and Function Overriding. Overloading is the practice of supplying more than one definition for a given function name in the same scope. The compiler is left to pick the appropriate version of the function or operator based on the arguments with which it is called. Overriding refers to the modifications made in the sub class to the inherited methods from the base class to change their behavior.

Question - 139 : - What is Operator overloading ?

Answer - 139 : - When an operator is overloaded, it takes on an additional meaning relative to a certain class. But it can still retain all of its old meanings. Examples: 1) The operators >> and << may be used for I/O operations because in the header, they are overloaded. 2) In a stack class it is possible to overload the + operator so that it appends the contents of one stack to the contents of another. But the + operator still retains its original meaning relative to other types of data.

Question - 140 : - What are Templates

Answer - 140 : - C++ Templates allow u to generate families of functions or classes that can operate on a variety of different data types, freeing you from the need to create a separate function or class for each type. Using templates, u have the convenience of writing a single generic function or class definition, which the compiler automatically translates into a specific version of the function or class, for each of the different data types that your program actually uses. Many data structures and algorithms can be defined independently of the type of data they work with. You can increase the amount of shared code by separating data-dependent portions from data-independent portions, and templates were introduced to help you do that.


NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners