LANGUAGES | C | C LANGUAGE INTERVIEW QUESTION AND ANSWERS | 09

 What is the difference between strdup and strcpy - What is this pointer

C Language Interview Question and Answers:

41. 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.

42. 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.

43. 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.

44. 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)

45. 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.

No comments:

Post a Comment