C Language Interview Question and Answers

41. What is the use of typedef?
  The typedef help in easier modification when the programs are ported to another machine.A descriptive new name given to the existing data type may be easier to understand the code.
 
Vinoth Kumar,says Apr 01,2014
The C programming language provides a keyword called typedef, which you can use to give a type a new name. The purpose of typedef is to assign alternative names to existing types, most often those whose standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another.
Your Name Your Email-ID
Your Answer
42. What are the differences between new and malloc?
 
  • New initializes the allocated memory by calling the constructor. Memory allocated with new should be released with delete.
  • Malloc allocates uninitialized memory.
  • The allocated memory has to be released with free.new automatically calls the constructor while malloc(dosen’t)
 
Your Name Your Email-ID
Your Answer
43. What is the difference between strdup and strcpy?
  Both copy a string. strcpy wants a buffer to copy into. strdup allocates a buffer using malloc().
Unlike strcpy(), strdup() is not specified by ANSI.
 
Your Name Your Email-ID
Your Answer
44. What is this pointer?
  It is a pointer that points to the current object. This can be used to access the members of the current object with the help of the arrow operator.
 
Your Name Your Email-ID
Your Answer
45. What is friend function?
  The function declaration should be preceded by the keyword friend.The function definitions does not use either the keyword or the scope operator ::. The functions that are declared with the keyword friend as friend function.Thus, a friend function is an ordinary function or a member of another class.
 
Sumaiyya, says Jan 24,2014
A friend function is used for accessing the non-public members of a class. A class can allow non-member functions and other classes to access its own private data, by making them friends. Thus, a friend function is an ordinary function or a member of another class. Need for Friend Function: when a data is declared as private inside a class, then it is not accessible from outside the class. A function that is not a member or an external class will not be able to access the private data. A programmer may have a situation where he or she would need to access private data from non-member functions and external classes. For handling such cases, the concept of Friend functions is a useful tool.
Your Name Your Email-ID
Your Answer